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 zzzeek
Recipients zzzeek
Date 2009-05-30.20:07:40
SpamBayes Score 1.5821916e-10
Marked as misclassified No
Message-id <1243714064.27.0.0793186526424.issue6149@psf.upfronthosting.co.za>
In-reply-to
Content
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:

import weakref

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

w = weakref.WeakValueDictionary(mydict)

assert w[5]
History
Date User Action Args
2009-05-30 20:07:44zzzeeksetrecipients: + zzzeek
2009-05-30 20:07:44zzzeeksetmessageid: <1243714064.27.0.0793186526424.issue6149@psf.upfronthosting.co.za>
2009-05-30 20:07:41zzzeeklinkissue6149 messages
2009-05-30 20:07:40zzzeekcreate