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
{{ message }}
Repository navigation
MyPy forgets callable type guard in lambda in return statement of function with hinted return type #15862
There seems to be some strange interaction between hinted return types, lambdas and the callable type guard.
To Reproduce
Here is a minimal example, together with some related examples that are not broken, showing that the return type, lambda and callable are all required for this to break:
Activity
hauntsaninja commentedon Aug 13, 2023
Thanks for the issue!
The underlying reason is that closures in Python are late binding, see https://mypy.readthedocs.io/en/stable/common_issues.html#narrowing-and-inner-functions.
mypy recently improved heuristics here (see #2608), but I guess not quite well enough to avoid the false positive in your case.
hauntsaninja commentedon Jan 4, 2024
Fixed by #16407