Raymond Hettinger added the comment: [Anthony Lee] > The use case is to generate a mapping of weakly-held objects > to unique ids, with something like > > id_map = WeakKeyDictionaryWithMissing(lambda *, _counter=itertools.count(): > > next(_counter))
Where are you keeping hard references to the keys? ISTM, you only have a weak reference, so the object has no hard references. Entries in the dictionary are discarded when there is no longer a strong reference to the key. Why did you decide to use a dictionary? AFAICT, nothing external to the dictionary knows about the keys so there is no way to do lookups. Overall, it doesn't seem like a WeakKeyDictionary with a __missing__() method is the right approach for this problem. It makes me question where it makes any sense at all to auto-generate missing keys for a WeakKeyDictionary. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue31254> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com