Document undesirable generator expression behavior in test and fix one case#20594
Merged
hauntsaninja merged 1 commit intoJan 18, 2026
Conversation
michaelm-openai
commented
Jan 16, 2026
| take_iterable(reveal_type(1 for _ in [])) # N: Revealed type is "typing.Generator[builtins.int, None, None]" | ||
|
|
||
| # NOTE: Type is revealed for every overload tried | ||
| # TODO: Overload shouldn't fail if expression contains an error that shouldn't affect the inferred type. |
Contributor
Author
There was a problem hiding this comment.
I guess this is not strictly true, since it could be that the overload adds contextual information that causes the expression to have an error. Maybe a better behavior is if every overload contains errors, then pick the one with a valid inferred expression type.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a test case to explicitly demonstrate behavior which I believe has the same root cause as #18026
The short explanation is that if any get produced while inferring the type of a generator expression which is being passed to an overloaded function, the overload will be considered failed, even if the error has no effect on the inferred type of the generator expression.
One experiment to try that might address this could be to only fail the overload if the inferred type contains
AnyType(TypeOfAny.from_error).For now, only fix the specific case where the "error" is a
reveal_typenote.