Bug Report
mypy mark as unreachable code that is perfectly reachable, perhaps because it interprets an instance variable typed as Optional to always be None.
To Reproduce
fromtypingimportOptional# executed with --warn-unreachableclassA:
x: Optional[int]
defexecute(self) ->None:
self.x=Noneforiinrange(3):
ifself.xisNone:
self.x=10else:
self.x=20# error: Statement is unreachable [unreachable]print(self.x)
a=A()
a.execute()
Gist
Playground URL
Expected Behavior
No errors.
Actual Behavior
Showing: error: Statement is unreachable [unreachable]
Your Environment
- Mypy version used: 0.982
- Mypy command-line flags: --warn-unreachable
- Mypy configuration options from
mypy.ini (and other config files): - Python version used: 3.10
Bug Report
mypy mark as unreachable code that is perfectly reachable, perhaps because it interprets an instance variable typed as Optional to always be None.
To Reproduce
Gist
Playground URL
Expected Behavior
No errors.
Actual Behavior
Showing:
error: Statement is unreachable [unreachable]Your Environment
mypy.ini(and other config files):