python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
17.85k stars 2.74k forks source link

(🐞) `isinstance` doesn't work with unions containing `None` #17413

Closed KotlinIsland closed 1 week ago

KotlinIsland commented 1 week ago
value: str | bool | None
assert not isinstance(value, str | None)
reveal_type(value)  # str | bool | None
value: object
assert isinstance(value, str | None)
reveal_type(value)  # object
hauntsaninja commented 1 week ago

Thanks for the issue, looks pretty easy to fix