Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2918,7 +2918,7 @@ def infer_overload_return_type(

for typ in plausible_targets:
assert self.msg is self.chk.msg
with self.msg.filter_errors() as w:
with self.msg.filter_errors(filter_revealed_type=True) as w:
with self.chk.local_type_map as m:
ret_type, infer_type = self.check_call(
callee=typ,
Expand Down
21 changes: 21 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,27 @@ if int():
b = (x for x in a) # E: Generator has incompatible item type "Callable[[], str]"; expected "Callable[[], int]"
[builtins fixtures/list.pyi]

[case testGeneratorNoSpuriousError]
from typing import Iterable, overload

@overload
def take_iterable(iterable: Iterable[bool], /) -> None: ...
@overload
def take_iterable(iterable: Iterable[int], /) -> None: ...
def take_iterable(iterable): pass

take_iterable(1 for _ in [])
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.

take_iterable(reveal_type(1 if (-"") else 1 for _ in [])) # N: Revealed type is "typing.Generator[builtins.int, None, None]" \
# N: Revealed type is "typing.Generator[builtins.bool, None, None]" \
# E: Generator has incompatible item type "int"; expected "bool" \
# E: Unsupported operand type for unary - ("str")

[builtins fixtures/for.pyi]

-- Conditional expressions
-- -----------------------

Expand Down