Closed LuKuangChen closed 2 years ago
a4a71ae 2021-12-28
from typing import Optional def f(x: Optional[str]) -> str: while True: if x is None: break return x print(f(None))
This program borrowed from cinder/3.8/Lib/test/test_compiler/test_static/tests.py L5536. This test is labeled test_break_condition.
cinder/3.8/Lib/test/test_compiler/test_static/tests.py
test_break_condition
The program type-checks and prints None, although the function f is annotated to return a str.
None
f
str
The program should be rejected by the type checker.
Fixed by 8ea180376e9dcbc92f61bc44434c29b15b637383
a4a71ae 2021-12-28
What program did you run?
This program borrowed from
cinder/3.8/Lib/test/test_compiler/test_static/tests.py
L5536. This test is labeledtest_break_condition
.What happened?
The program type-checks and prints
None
, although the functionf
is annotated to return astr
.What should have happened?
The program should be rejected by the type checker.