Message300816
[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. |
|
Date |
User |
Action |
Args |
2017-08-25 00:31:23 | rhettinger | set | recipients:
+ rhettinger, pitrou, Antony.Lee |
2017-08-25 00:31:23 | rhettinger | set | messageid: <1503621083.66.0.735107460495.issue31254@psf.upfronthosting.co.za> |
2017-08-25 00:31:23 | rhettinger | link | issue31254 messages |
2017-08-25 00:31:22 | rhettinger | create | |
|