mypy
mypy copied to clipboard
Union can cause Iterator to require a return statement
Bug Report
Iterator doesn't require a return statement except when used in an union.
To Reproduce
from typing import Iterator, Union
Type = Union[Iterator[int], int]
def foo() -> Type:
yield 1
Actual Behavior
error: Missing return statement [return]
Expected behavior
I expected Mypy to not return any errors like
from typing import Iterator, Union
Type = Iterator[int]
def foo() -> Type:
yield 1
Your Environment
- Mypy version used: 1.10.0 (Works on 1.9.0)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.12