You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[1.20 regression] narrowing failure with unrelated boolean #21204
This passes in MyPy 1.19.1, and is ostensibly correct code -- this is a minimised version, but the original performs similar checks with enum.StrEnum, so not that esoteric.
If the value.__class__.__str__ == FancyInteger.__str__ comparison is removed, or split to a new if statement, the error fails to reproduce.
$ uvx mypy==1.20
bug.py:14: error: Item "str" of "str | int" has no attribute "name" [union-attr]
bug.py:14: error: Item "int" of "str | int" has no attribute "name" [union-attr]
Found 2 errors in 1 file (checked 1 source file)
$ uvx mypy==1.19.1
Success: no issues found in 1 source file
Your Environment
Mypy version used: 1.20 & 1.19.1
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): None
Thanks for the issue. I thiiiiiink the change in 1.20 is actually just exposing a pre-existing issue, e.g. something like this fails on mypy 1.19 as well:
class A:
tag: int
class B:
tag: int
name = "b"
class C:
tag: str
def stringify(value: A | B | C) -> str:
if isinstance(value.tag, int) and isinstance(value, B):
reveal_type(value)
return value.name
return ""
Activity
brianschubert commentedon Apr 12, 2026
Thanks, bisects to ad30be8, cc @hauntsaninja
AA-Turner commentedon Apr 12, 2026
thanks @brianschubert, amazingly fast!
hauntsaninja commentedon Apr 12, 2026
Thanks for the issue. I thiiiiiink the change in 1.20 is actually just exposing a pre-existing issue, e.g. something like this fails on mypy 1.19 as well:
Correctly aggregate narrowing information on parent expressions
Correctly aggregate narrowing information on parent expressions (pyth…
Correctly aggregate narrowing information on parent expressions (#21206)