# 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]
What version of Static Python are you using?
9965302 2021-07-21
What program did you run?
What happened?
A dynamic error was raised.
What should have happened?
We expected a static error because the type checker has enough information to push
int
andstr
into the comprehension. This behavior has been illustrated by a similar program, which raises a static error.