New submission from conchylicultor <etiennefg....@gmail.com>:
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)` ---------- components: Library (Lib) messages: 393707 nosy: conchylicultor priority: normal severity: normal status: open title: WeakKeyDictionary should support lookup by id instead of hash type: enhancement versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44140> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com