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

What would it take to make unhashable dict key a static error? #40

Open
LuKuangChen opened this issue Jul 15, 2021 · 1 comment
Open
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?

# compile_nested_dict_dict_key.py

from __static__ import CheckedDict

class B: pass

class D(B): pass

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

print(testfunc())

What happened?

The program raises a runtime error.

TypeError: unhashable type: 'dict[B, int]'

What should have happened?

We expected a compile-time error complaining that CheckedDict[B, int] is unhashable. Maybe the type system can look for a __hash__ method.

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

carljm commented Apr 5, 2022

We want it to be possible to use types that are not known to SP at compile time in a CheckedDict, in which case we cannot know if they are hashable. So I think the best that we could do here is opportunistically emit a static error if a type which is known to be not-hashable is used as CheckedDict key, but we can't prevent this runtime TypeError in all cases.

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

3 participants