Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the float type is unbound in a simple program #42

Closed
LuKuangChen opened this issue Jul 19, 2021 · 2 comments
Closed

the float type is unbound in a simple program #42

LuKuangChen opened this issue Jul 19, 2021 · 2 comments
Labels
sp-correctness static python correctness staticpython static python issues

Comments

@LuKuangChen
Copy link

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]

@jbower-fb jbower-fb added staticpython static python issues sp-correctness static python correctness labels Jul 28, 2021
@DinoV
Copy link
Contributor

DinoV commented Dec 20, 2021

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
Copy link
Contributor

carljm commented Apr 5, 2022

Closing this as a special case of #49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sp-correctness static python correctness staticpython static python issues
Projects
None yet
Development

No branches or pull requests

4 participants