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
Narrowing an optional class type to an unrelated Protocol causes a false unreachable error #12802
If Y is a runtime-checkable protocol which is not implemented by the class X, then mypy will erroneously consider the print statement in the following to be unreachable:
> mypy --warn-unreachable foo.py
foo.py:25: note: Revealed type is "Union[foo.X, None]"
foo.py:27: note: Revealed type is "foo.<subclass of "X" and "Y">1"
foo.py:32: note: Revealed type is "foo.X"
foo.py:34: note: Revealed type is "foo.<subclass of "X" and "Y">1"
Success: no issues found in 1 source file
Actual Behavior
> mypy --warn-unreachable foo.py
foo.py:25: note: Revealed type is "Union[foo.X, None]"
foo.py:27: error: Statement is unreachable
foo.py:32: note: Revealed type is "foo.X"
foo.py:34: note: Revealed type is "foo.<subclass of "X" and "Y">1"
Found 1 error in 1 file (checked 1 source file)
(Running the script demonstrates that there is no actual unreachable code at runtime.)
Your Environment
Mypy version used: mypy 0.950 (compiled: yes)
Mypy command-line flags: --warn-unreachable
Mypy configuration options from mypy.ini (and other config files): None
Python version used: Python 3.10.4
Operating system and version:
Edition Windows 10 Business
Version 21H1
Installed on 2.8.2021
OS build 19043.1706
Experience Windows Feature Experience Pack 120.2212.4170.0
Activity