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

better static checks on initializing CheckedDict variables with dictionary literals #60

Open
LuKuangChen opened this issue Dec 21, 2021 · 1 comment
Labels
sp-adoption static python adoption utilities staticpython static python issues

Comments

@LuKuangChen
Copy link

a4a71ae
2021-12-20

What program did you run?

from __static__ import CheckedDict

class B: pass

def testfunc():
x: CheckedDict[B, int] = {object():42}
return x

This program is found in cinder/3.8/Lib/test/test_compiler/test_static/tests.py. This test is labeled test_compile_checked_dict_with_annotation_wrong_key_type. There is a similar test labeled test_compile_checked_dict_with_annotation_wrong_value_type.

What happened?

compiler.errors.TypedSyntaxError: type mismatch: Exact[chkdict[object, Literal[42]]] cannot be assigned to Exact[chkdict[__main__.B, int]]

What should have happened?

We expected a compile-time error complaining that object cannot be assigned to B. In general, we expect that everytime the type checker sees x: CheckedDict[T1, T2] = { e1: e2, ... }, it checks every key expression e1 against T1, and every e2 against T2.

@carljm carljm added sp-ux static python user experience issues staticpython static python issues labels Jan 11, 2022
@DinoV DinoV added sp-adoption static python adoption utilities and removed sp-ux static python user experience issues labels Jan 11, 2022
@carljm carljm changed the title initialize CheckedDict variables with dictionary literals better static checks on initializing CheckedDict variables with dictionary literals Apr 7, 2022
@carljm
Copy link
Contributor

carljm commented Apr 7, 2022

@DinoV did b69cb74 also fix this issue? It looks like it might have, but it didn't explicitly add a test with literal RHS.

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

No branches or pull requests

3 participants