Message393707
WeakKeyDictionary are great to "associate additional data with an object owned by other parts of an application", as quoted from the doc: https://docs.python.org/3/library/weakref.html#weakref.WeakKeyDictionary
However, this currently only works for hashable types. Non-hashables are not supported:
```
@dataclass
class A:
pass
a = A()
d = weakref.WeakKeyDictionary()
d[a] = 3 # TypeError: unhashable type: 'A'
```
With regular dict, this could be easilly solved by using `d[id(a)] = 3`, but WeakKeyDictionary don't accept `int` of course. I cannot wrap the object either as the weakref would not be attached to the original object, but the wrapper.
It would be great to be able to force WeakKeyDictionary to perform lookup on `id` internally. Like `d = WeakKeyDictionary(use_id_lookup=True)` |
|
Date |
User |
Action |
Args |
2021-05-15 08:42:52 | conchylicultor | set | recipients:
+ conchylicultor |
2021-05-15 08:42:51 | conchylicultor | set | messageid: <1621068171.99.0.542983196926.issue44140@roundup.psfhosted.org> |
2021-05-15 08:42:51 | conchylicultor | link | issue44140 messages |
2021-05-15 08:42:51 | conchylicultor | create | |
|