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 barry
Recipients
Date 2002-03-13.05:29:20
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
In Python 2.1.2, WeakValueDictionary.setdefault() is
broken:

Python 2.1.2 (#1, Jan 27 2002, 18:54:41) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)]
on linux2
Type "copyright", "credits" or "license" for more
information.
>>> import weakref
>>> d = weakref.WeakValueDictionary()
>>> class C: pass
... 
>>> d.setdefault('yes', C())
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.1/weakref.py", line 91,
in setdefault
    ref = ref(default, remove)
UnboundLocalError: local variable 'ref' referenced
before assignment

Attached is a simple patch, along with a test case. 
This is a bug fix candidate for Python 2.1.3, should
there be one.  It is not necessary for Python 2.2,
although you may want to port the test forward.
History
Date User Action Args
2007-08-23 13:59:47adminlinkissue529273 messages
2007-08-23 13:59:47admincreate