Skip to content

Conversation

@michaelm-openai
Copy link

@michaelm-openai michaelm-openai commented Jan 16, 2026

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_type note.

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.
Copy link
Author

@michaelm-openai michaelm-openai Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant