Title: WeakValueDictionary constructor ported to Python 3.0 incorrectly
Type: crash Stage: patch review
Components: Library (Lib) Versions: Python 3.1
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, zzzeek
Priority: high Keywords: patch

Created on 2009-05-30 20:07 by zzzeek, last changed 2009-05-30 21:05 by pitrou. This issue is now closed.

File name Uploaded Description Edit
issue6149.patch pitrou, 2009-05-30 20:37
Messages (3)
msg88577 - (view) Author: mike bayer (zzzeek) * Date: 2009-05-30 20:07
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]
msg88578 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-05-30 20:37
Here is a patch for 3.1.
msg88581 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-05-30 21:05
Fixed in r73063. Thanks!
Date User Action Args
2009-05-30 21:05:29pitrousetstatus: open -> closed
resolution: fixed
messages: + msg88581
2009-05-30 20:38:00pitrousetfiles: + issue6149.patch
priority: high

versions: + Python 3.1, - Python 3.0
keywords: + patch
nosy: + pitrou

messages: + msg88578
stage: patch review
2009-05-30 20:08:07zzzeeksettype: crash
components: + Library (Lib)
2009-05-30 20:07:42zzzeekcreate