facebookincubator / cinder

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

calling CheckedDict #43

Closed LuKuangChen closed 2 years ago

LuKuangChen commented 3 years ago

What version of Static Python are you using?

9965302 2021-07-21

What program did you run?

# calling_CheckedDict.py
from __static__ import CheckedDict

def testfunc():
    x = CheckedDict[int, str]({int(i): int(i) for i in
                               range(1, 5)})
    return x

testfunc()

What happened?

A dynamic error was raised.

TypeError: bad value 'int' for dict[int, str]

What should have happened?

We expected a static error because the type checker has enough information to push int and str into the comprehension. This behavior has been illustrated by a similar program, which raises a static error.

# calling_CheckedDict_variant.py
from __static__ import CheckedDict

def testfunc():
    x: CheckedDict[int, str] = {int(i): int(i) for i in
                               range(1, 5)}
    return x

testfunc()

# compiler.static.TypedSyntaxError: type mismatch: 
# Exact[chkdict[Exact[int], Exact[int]]] cannot be assigned to chkdict[int, str] 
carljm commented 2 years ago

Looks like this was fixed a while back!