Mypy v1.20.0 no longer detects variable type narrowing via reassignment in this case.
from typing import Iterable
def foo(args: Iterable[str | int] | str | int) -> Iterable[str]:
if isinstance(args, (str, int)):
args = (args,)
args = (
arg if isinstance(arg, str) else str(arg)
for arg in args
)
return args
I expect this code to type check successfully with mypy 1.20.0 like it did with 1.19.1
main.py:10: error: Incompatible return value type (got "Generator[str | int, None, None]", expected "Iterable[str]") [return-value]
Bug Report
Mypy v1.20.0 no longer detects variable type narrowing via reassignment in this case.
To Reproduce
Expected Behavior
I expect this code to type check successfully with mypy 1.20.0 like it did with 1.19.1
Actual Behavior
Your Environment