-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-reachabilityDetecting unreachable codeDetecting unreachable code
Description
Bug Report
This is probably already a bug report but the only place I know where this was mentioned was #13607 (comment).
Including | None
in a type makes isinstance
type narrowing incorrectly report unreachability. This isn't only a problem with | None
.
To Reproduce
class SymbolTableNode: pass
class FuncBase: pass
def bad(node: SymbolTableNode | None) -> None:
assert isinstance(node, FuncBase)
reveal_type(node) # unreachable
def good(node: SymbolTableNode) -> None:
assert isinstance(node, FuncBase)
reveal_type(node) # <subclass of SymbolTableNode and FuncBase>
Expected Behavior
No unreachable statements.
Actual Behavior
Unreachable reveal_type(node)
.
Your Environment
Reproduced in mypy-play.
- Mypy version used: 1.18.2
- Mypy command-line flags:
--warn-unreachable
- Mypy configuration options from
mypy.ini
(and other config files): N/A - Python version used: 3.12
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-reachabilityDetecting unreachable codeDetecting unreachable code