You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WeakValueDictionary constructor ported to Python 3.0 incorrectly #50399
The constructor for WeakValueDictionary does not obey the contract
documented in its comments:
# We inherit the constructor without worrying about the input
# dictionary; since it uses our .update() method, we get the right
# checks
yet it initializes with:
self.data=d= {}
d.update(*args, **kw)
i.e. the "update()" method of dict, so that a dict passed to the
constructor initializes non-weakrefed values in the dict which is
completely invalid state.
Contrast to that of 2.6, which properly uses the superclass:
UserDict.UserDict.__init__(self, *args, **kw)
A simple test which raises an exception on 3.0.1 is as follows:
Activity
zzzeek commentedon May 30, 2009
The constructor for WeakValueDictionary does not obey the contract
documented in its comments:
yet it initializes with:
i.e. the "update()" method of dict, so that a dict passed to the
constructor initializes non-weakrefed values in the dict which is
completely invalid state.
Contrast to that of 2.6, which properly uses the superclass:
A simple test which raises an exception on 3.0.1 is as follows:
assert w[5]
pitrou commentedon May 30, 2009
Here is a patch for 3.1.
pitrou commentedon May 30, 2009
Fixed in r73063. Thanks!