Author zzzeek
Recipients zzzeek
Date 2009-05-30.20:07:40
SpamBayes Score 1.58219e-10
Marked as misclassified No
Message-id <>
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: = 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:

import weakref

class Foo(object):
mydict = dict((k, Foo()) for k in range(10))

w = weakref.WeakValueDictionary(mydict)

assert w[5]
Date User Action Args
2009-05-30 20:07:44zzzeeksetrecipients: + zzzeek
2009-05-30 20:07:44zzzeeksetmessageid: <>
2009-05-30 20:07:41zzzeeklinkissue6149 messages
2009-05-30 20:07:40zzzeekcreate