Open
Description
Bug Report
Split off from #7374 (comment)
To Reproduce
from typing import Generator, NoReturn, Union
def inf() -> Generator[str, None, NoReturn]:
while True:
yield "xyz"
def generate(x: Union[str, int]) -> Generator[str, None, int]:
if isinstance(x, str):
yield from inf() # `yield from` will never return, because the generator never returns
return x # error: Incompatible return value type (got "Union[str, int]", expected "int")
Expected Behavior
No error
Actual Behavior
An error.
Your Environment
Reproduced in mypy-play.
- Mypy version used: 1.16.1
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini
(and other config files): N/A - Python version used: 3.12