Bug Report
If the condition of an if block is a Callable (or not Callable), the body of the else (or if) is not analyzed by mypy.
To Reproduce
Run mypy on:
def func() -> bool:
return True
if not func:
a: str = 4
reveal_type(a)
else:
b: str = 4
reveal_type(b)
if func:
c: str = 4
reveal_type(c)
else:
d: str = 4
reveal_type(d)
Expected Behavior
Either:
test.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "str")
test.py:6: note: Revealed type is "builtins.str"
test.py:8: error: Incompatible types in assignment (expression has type "int", variable has type "str")
test.py:9: note: Revealed type is "builtins.str"
test.py:12: error: Incompatible types in assignment (expression has type "int", variable has type "str")
test.py:13: note: Revealed type is "builtins.str"
test.py:15: error: Incompatible types in assignment (expression has type "int", variable has type "str")
test.py:16: note: Revealed type is "builtins.str"
or maybe statement-unreachable on lines 5 and 15?
Actual Behavior
test.py:8: error: Incompatible types in assignment (expression has type "int", variable has type "str")
test.py:9: note: Revealed type is "builtins.str"
test.py:12: error: Incompatible types in assignment (expression has type "int", variable has type "str")
test.py:13: note: Revealed type is "builtins.str"
Your Environment
- Mypy version used:
0.910
- Mypy command-line flags: Just
mypy test.py.
- Mypy configuration options from
mypy.ini (and other config files): None
- Python version used:
3.8.3
- Operating system and version: Windows 10 Pro 21H1
Bug Report
If the condition of an
ifblock is aCallable(ornot Callable), the body of theelse(orif) is not analyzed by mypy.To Reproduce
Run
mypyon:Expected Behavior
Either:
or maybe
statement-unreachableon lines 5 and 15?Actual Behavior
Your Environment
0.910mypy test.py.mypy.ini(and other config files): None3.8.3