isinstance(foo, SomeType | None)
fails to narrow variable, while isinstance(foo, SomeType | type(None))
succeeds
#17530
Labels
bug
mypy got something wrong
Bug Report
It appears that
isinstance(a, str | None)
fails to narrow the variablea
tostr | None
. Its type remains to bestr | int | None
.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=883cae3c57a4ddca5c4406a0f7cd89d3
Expected Behavior
I would expect that
isinstance(a, str | None)
would narrow the variablea
tostr | None
.Actual Behavior
The type of
a
is not narrowed tostr | None
and remains of typestr | int | None
.Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: