-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect inference of Callable
generic typing
#5199
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-type-variables
Comments
I believe this is a duplicate of #4872. It looks like just another example where mypy inference engine is being to "greedy". Actually after some thinking it looks like fixing these particular examples might be tricky, so I would like to keep this one open. |
ilevkivskyi
added
bug
mypy got something wrong
topic-type-variables
priority-1-normal
false-positive
mypy gave an error on correct code
labels
Jun 12, 2018
I'm also interested in a fix for this as I encountered exactly the same issue today. :) |
ilevkivskyi
added a commit
that referenced
this issue
Oct 2, 2018
Fixes #4872 Fixes #3876 Fixes #2678 Fixes #5199 Fixes #5493 (It also fixes a bunch of similar issues previously closed as duplicates, except one, see below). This PR fixes a problems when mypy commits to soon to using outer context for type inference. This is done by: * Postponing inference to inner (argument) context in situations where type inferred from outer (return) context doesn't satisfy bounds or constraints. * Adding a special case for situation where optional return is inferred against optional context. In such situation, unwrapping the optional is a better idea in 99% of cases. (Note: this doesn't affect type safety, only gives empirically more reasonable inferred types.) In general, instead of adding a special case, it would be better to use inner and outer context at the same time, but this a big change (see comment in code), and using the simple special case fixes majority of issues. Among reported issues, only #5311 will stay unfixed.
TV4Fun
pushed a commit
to TV4Fun/mypy
that referenced
this issue
Oct 4, 2018
Fixes python#4872 Fixes python#3876 Fixes python#2678 Fixes python#5199 Fixes python#5493 (It also fixes a bunch of similar issues previously closed as duplicates, except one, see below). This PR fixes a problems when mypy commits to soon to using outer context for type inference. This is done by: * Postponing inference to inner (argument) context in situations where type inferred from outer (return) context doesn't satisfy bounds or constraints. * Adding a special case for situation where optional return is inferred against optional context. In such situation, unwrapping the optional is a better idea in 99% of cases. (Note: this doesn't affect type safety, only gives empirically more reasonable inferred types.) In general, instead of adding a special case, it would be better to use inner and outer context at the same time, but this a big change (see comment in code), and using the simple special case fixes majority of issues. Among reported issues, only python#5311 will stay unfixed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-type-variables
A little bit complicated, though I believe the lambda should be inferenced as
Callable[[C], bool]
though it appears to instead be inferenced asCallable[[Optional[C]], bool]
A related, less-lambda-y reproduction:
The text was updated successfully, but these errors were encountered: