Bug Report
There was a regression in narrowing with isinstance checks from 1.19 to 1.20. This seems to only happen when the same object is narrowed multiple times. For example, this works correct if removing the outer is not None guard and the | None from the argument.
To Reproduce
mypy playground link
from __future__ importannotationsdef_score_test(
exc: BaseException|None, expected_excs: set[type[BaseException]]
) ->None:
ifexcisnotNone:
reveal_type(exc)
reveal_type(expected_excs) # Revealed type is "BaseException"reveal_type(tuple(expected_excs)) # Revealed type is "tuple[type[BaseException], ...]"ifisinstance(exc, tuple(expected_excs)):
reveal_type(exc) # Revealed type is "object"returnlogexc(exc) # Argument 1 to "logexc" has incompatible type "object"; expected "BaseException | None"deflogexc(
exc: BaseException|None
) ->None:
...
Bug Report
There was a regression in narrowing with isinstance checks from 1.19 to 1.20. This seems to only happen when the same object is narrowed multiple times. For example, this works correct if removing the outer
is not Noneguard and the| Nonefrom the argument.To Reproduce
mypy playground link