[New-bugs-announce] [issue46925] Replace key if not identical to old key in dict
report at bugs.python.org
Fri Mar 4 18:25:53 EST 2022
New submission from Malthe Borch <mborch at gmail.com>:
When a key that is equal to an existing key (but not the same object identity) is used to set a new value, the key itself is not replaced.
This manifests perhaps most clearly in `weakref.WeakKeyDictionary` where keys can mysteriously disappear.
Consider two equal keys, k1 and k2:
d = WeakKeyDictionary()
d[k1] = 1
d[k2] = 2
We would expect the dictionary to have a single entry k2 => 2. But in fact it is empty now.
components: Library (Lib)
title: Replace key if not identical to old key in dict
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce