]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix SF bug #529273: WeakValueDictionary.setdefault() raised UnboundLocalError
authorFred Drake <fdrake@acm.org>
Wed, 13 Mar 2002 05:47:26 +0000 (05:47 +0000)
committerFred Drake <fdrake@acm.org>
Wed, 13 Mar 2002 05:47:26 +0000 (05:47 +0000)
since it used the name of a global function as the name of a local.  The
patch is almost identical to that submitted with the bug report.

Lib/weakref.py

index b6b45282d06582ca7d9cbf49ede1967a1a2b7741..7696c0fcb23ee005e85a6e5d72447925c579aa97 100644 (file)
@@ -84,15 +84,14 @@ class WeakValueDictionary(UserDict.UserDict):
 
     def setdefault(self, key, default):
         try:
-            ref = self.data[key]
+            wr = self.data[key]
         except KeyError:
             def remove(o, data=self.data, key=key):
                 del data[key]
-            ref = ref(default, remove)
-            self.data[key] = ref
+            self.data[key] = ref(default, remove)
             return default
         else:
-            return ref()
+            return wr()
 
     def update(self, dict):
         d = self.data