facebookincubator / cinder

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

the float type is unbound in a simple program #42

Closed LuKuangChen closed 2 years ago

LuKuangChen commented 3 years ago

What version of Static Python are you using?

9965302 2021-07-15

What program did you run?

# float_unbound.py

def f(x: float):
    reveal_type(x)

What happened?

The variable x has type dynamic.

compiler.static.TypedSyntaxError: reveal_type(x): 'dynamic', 'x' has declared type 'dynamic' and local type 'dynamic'

What should have happened?

We expected that the variable x has type float because of the annotation x: float. The function float has a type and float(1) has the type Exact[float]

DinoV commented 2 years ago

This is currently due to a combination of behaviors. First, we treat a float annotation as float | int because the Python type checkers treat int as being compatible with float. We then treat arguments which are declared as unions as dynamic because we don't support runtime type checking of them, so we can't keep them typed otherwise the compiler could narrow through isinstance checks incorrectly. If we solved the second issue we'd then report this as int | float.

carljm commented 2 years ago

Closing this as a special case of #49