facebookincubator / cinder

Cinder is Meta's internal performance-oriented production version of CPython.
https://trycinder.com
Other
3.42k stars 122 forks source link

Add type checking of implicit None return #62

Closed LuKuangChen closed 2 years ago

LuKuangChen commented 2 years ago

a4a71ae 2021-12-28

What program did you run?

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.

What happened?

The program type-checks and prints None, although the function f is annotated to return a str.

What should have happened?

The program should be rejected by the type checker.

carljm commented 2 years ago

Fixed by 8ea180376e9dcbc92f61bc44434c29b15b637383