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
classSymbolTableNode: passclassFuncBase: passdefbad(node: SymbolTableNode|None) ->None:
assertisinstance(node, FuncBase)
reveal_type(node) # unreachabledefgood(node: SymbolTableNode) ->None:
assertisinstance(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
Bug Report
This is probably already a bug report but the only place I know where this was mentioned was #13607 (comment).
Including
| Nonein a type makesisinstancetype narrowing incorrectly report unreachability. This isn't only a problem with| None.To Reproduce
Expected Behavior
No unreachable statements.
Actual Behavior
Unreachable
reveal_type(node).Your Environment
Reproduced in mypy-play.
--warn-unreachablemypy.ini(and other config files): N/A