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

Open
#40 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
compilers

Research direction

Start by running compile_nested_dict_dict_key.py with the reported Static Python revision and inspect how CheckedDict[B, int] is treated as a key. Determine whether the type system can use hash; done means the example produces a compile-time error rather than the runtime TypeError.

Written by the indexing model from the issue text.

Description

sp-correctness staticpython
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.

Dominant language
Python
Stars
3.8k
Forks
139
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebookincubator/MetaPython

All issues in facebookincubator/MetaPython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.