starlette icon indicating copy to clipboard operation
starlette copied to clipboard

Assert function arguments by type instead of name

Open Kludex opened this issue 3 years ago • 0 comments

Discussed in https://github.com/encode/starlette/discussions/1815

Originally posted by haggen August 19, 2022 https://github.com/encode/starlette/blob/f6ea760a80d8b109fb6afd1c03e9a33754e6bb5f/starlette/authentication.py#L29-L38

I'm not a Pythonista so forgive me if it is commonplace in Python, but in general it seems to me be a bad idea to assert that a given function has an argument with a given name. It limits freedom of the developer and makes everything more brittle.

Searching throughout the repository it looks like it's the only instance where it happens.

In my particular use case I was trying to use req instead of request given the frequency I have to type and reference it.

Would it be acceptable if we validated that the type of the function's arguments instead of their name?

Let me know and I'll begin working on a PR.

Thanks in advance.

Kludex avatar Aug 29 '22 04:08 Kludex