This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Antony.Lee, pitrou, rhettinger
Date 2017-08-25.00:31:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1503621083.66.0.735107460495.issue31254@psf.upfronthosting.co.za>
In-reply-to
Content
[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.
History
Date User Action Args
2017-08-25 00:31:23rhettingersetrecipients: + rhettinger, pitrou, Antony.Lee
2017-08-25 00:31:23rhettingersetmessageid: <1503621083.66.0.735107460495.issue31254@psf.upfronthosting.co.za>
2017-08-25 00:31:23rhettingerlinkissue31254 messages
2017-08-25 00:31:22rhettingercreate