You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you wrap a function containing required keyword arguments with a decorator, type checking doesn't behave as one might expect - if you call the function and it's missing those kwargs (and/or contains unexpected kwargs), the mypy type check succeeds.
This isn't a problem with decorators in general. It's specific to lru_cache, and it's because of the way lru_cache is defined in the typeshed stubs.
I agree it's not a mypy bug, so closing the issue is fine - but as I mentioned in the issue description, the actual decorator we implemented in our code is not lru_cache. I did some more research and the underlying issue is that while our function is type hinted, the decorator we wrote was not type hinted.
Bug Report
If you wrap a function containing required keyword arguments with a decorator, type checking doesn't behave as one might expect - if you call the function and it's missing those kwargs (and/or contains unexpected kwargs), the mypy type check succeeds.
To Reproduce
Run
mypy <filename>
- observe that it succeedsRun
python <filename>
- observe errorNote that the actual code I was testing in our codebase uses a different decorator. I just picked a random one that is publicly available
Expected Behavior
mypy returns a typecheck error because
required_param
is not setActual Behavior
Success: no issues found in 1 source file
if I try to execute this code, python raises the expected
TypeError: my_function() got an unexpected keyword argument 'color'
if I remove the decorator mypy correctly raises a typecheck error.
Your Environment
mypy.ini
(and other config files): None that would impact this caseThe text was updated successfully, but these errors were encountered: