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
Since arg is checked against None before sub() is even defined, we can't get to that definition if arg is None
Actual Behavior
mypy thinks that arg is still Optional[int] inside sub body:
main.py:4: note: Revealed type is "Union[builtins.int, None]"
main.py:9: note: Revealed type is "builtins.int"
main.py:12: note: Revealed type is "Union[builtins.int, None]"
main.py:13: error: Unsupported operand types for + ("None" and "int")
main.py:13: note: Left operand is of type "Optional[int]"
Found 1 error in 1 file (checked 1 source file)
Compare messages for lines 9 and 12.
Your Environment
Mypy version used: 0.971
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.10
Operating system and version: mypy-play playground, also on macOS with python 3.9 and mypy 0.961.
Pyright in VSCode gets it right:
The text was updated successfully, but these errors were encountered:
Bug Report
mypy does not respect None check in nested functions defined after the check.
To Reproduce
Typecheck this code with Python 3.10 and mypy 0.971:
Expected Behavior
Since
arg
is checked againstNone
beforesub()
is even defined, we can't get to that definition ifarg
isNone
Actual Behavior
mypy thinks that
arg
is stillOptional[int]
insidesub
body:Compare messages for lines 9 and 12.
Your Environment
mypy.ini
(and other config files): nonePyright in VSCode gets it right:
The text was updated successfully, but these errors were encountered: