basedmypy
basedmypy copied to clipboard
value with `Any` in union type does not narrow when assigned to variable with non-`Any` type
this does not happen in upstreamed mypy
Gist to reproduce
# mypy: allow-any-explicit=true
from typing import Any, cast
def any() -> Any: ...
foo: str = any() or "" # type:ignore[no-any-expr]
reveal_type(foo) # error: Expression type contains "Any" (has type "Any | str")
bar: str = any()
reveal_type(bar) # no error, revealed type is "str"
I'm not sure what you are expecting sorry. if you split the assgnments then basedmypy behaves the same as mypy
if assigning an Any to a variable that takes a str causes the variable to remain typed as a str, why does assigning an Any | str to a variable that takes a str change its type to Any | str?