[Python-checkins] r84498 - in python/branches/release31-maint: Lib/copy.py Lib/test/test_copy.py Misc/ACKS Misc/NEWS

antoine.pitrou python-checkins at python.org
Sat Sep 4 19:49:13 CEST 2010


Author: antoine.pitrou
Date: Sat Sep 4 19:49:13 2010
New Revision: 84498
Log:
Merged revisions 84495-84497 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
 r84495 | antoine.pitrou | 2010年09月04日 19:40:21 +0200 (sam., 04 sept. 2010) | 4 lines
 
 Issue #1100562: Fix deep-copying of objects derived from the list and dict types.
 Patch by Michele Orrù and Björn Lindqvist.
........
 r84496 | antoine.pitrou | 2010年09月04日 19:40:51 +0200 (sam., 04 sept. 2010) | 3 lines
 
 Fix Björn's name in ACKS.
........
 r84497 | antoine.pitrou | 2010年09月04日 19:46:44 +0200 (sam., 04 sept. 2010) | 3 lines
 
 Fix running the copy module from the command-line (however use{ful,less} it may be).
........
Modified:
 python/branches/release31-maint/ (props changed)
 python/branches/release31-maint/Lib/copy.py
 python/branches/release31-maint/Lib/test/test_copy.py
 python/branches/release31-maint/Misc/ACKS
 python/branches/release31-maint/Misc/NEWS
Modified: python/branches/release31-maint/Lib/copy.py
==============================================================================
--- python/branches/release31-maint/Lib/copy.py	(original)
+++ python/branches/release31-maint/Lib/copy.py	Sat Sep 4 19:49:13 2010
@@ -51,6 +51,7 @@
 import types
 import weakref
 from copyreg import dispatch_table
+import builtins
 
 class Error(Exception):
 pass
@@ -109,7 +110,7 @@
 if t is not None:
 d[t] = _copy_immutable
 for name in ("complex", "unicode"):
- t = globals()['__builtins__'].get(name)
+ t = getattr(builtins, name, None)
 if t is not None:
 d[t] = _copy_immutable
 
@@ -279,17 +280,7 @@
 args = deepcopy(args, memo)
 y = callable(*args)
 memo[id(x)] = y
- if listiter is not None:
- for item in listiter:
- if deep:
- item = deepcopy(item, memo)
- y.append(item)
- if dictiter is not None:
- for key, value in dictiter:
- if deep:
- key = deepcopy(key, memo)
- value = deepcopy(value, memo)
- y[key] = value
+
 if state:
 if deep:
 state = deepcopy(state, memo)
@@ -305,6 +296,18 @@
 if slotstate is not None:
 for key, value in slotstate.items():
 setattr(y, key, value)
+
+ if listiter is not None:
+ for item in listiter:
+ if deep:
+ item = deepcopy(item, memo)
+ y.append(item)
+ if dictiter is not None:
+ for key, value in dictiter:
+ if deep:
+ key = deepcopy(key, memo)
+ value = deepcopy(value, memo)
+ y[key] = value
 return y
 
 del d
@@ -366,6 +369,16 @@
 print(map(reprlib.repr, l1))
 print(map(reprlib.repr, l2))
 print(map(reprlib.repr, l3))
+ class odict(dict):
+ def __init__(self, d = {}):
+ self.a = 99
+ dict.__init__(self, d)
+ def __setitem__(self, k, i):
+ dict.__setitem__(self, k, i)
+ self.a
+ o = odict({"A" : "B"})
+ x = deepcopy(o)
+ print(o, x)
 
 if __name__ == '__main__':
 _test()
Modified: python/branches/release31-maint/Lib/test/test_copy.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_copy.py	(original)
+++ python/branches/release31-maint/Lib/test/test_copy.py	Sat Sep 4 19:49:13 2010
@@ -532,6 +532,26 @@
 self.assertEqual(x.foo, y.foo)
 self.assertTrue(x.foo is not y.foo)
 
+ def test_deepcopy_dict_subclass(self):
+ class C(dict):
+ def __init__(self, d=None):
+ if not d:
+ d = {}
+ self._keys = list(d.keys())
+ super().__init__(d)
+ def __setitem__(self, key, item):
+ super().__setitem__(key, item)
+ if key not in self._keys:
+ self._keys.append(key)
+ x = C(d={'foo':0})
+ y = copy.deepcopy(x)
+ self.assertEqual(x, y)
+ self.assertEqual(x._keys, y._keys)
+ self.assertTrue(x is not y)
+ x['bar'] = 1
+ self.assertNotEqual(x, y)
+ self.assertNotEqual(x._keys, y._keys)
+
 def test_copy_list_subclass(self):
 class C(list):
 pass
Modified: python/branches/release31-maint/Misc/ACKS
==============================================================================
--- python/branches/release31-maint/Misc/ACKS	(original)
+++ python/branches/release31-maint/Misc/ACKS	Sat Sep 4 19:49:13 2010
@@ -469,7 +469,7 @@
 Martin Ligr
 Grant Limberg
 Christopher Lindblad
-Bjorn Lindqvist
+Björn Lindqvist
 Per Lindqvist
 Eric Lindvall
 Gregor Lingl
Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Sat Sep 4 19:49:13 2010
@@ -105,6 +105,9 @@
 Library
 -------
 
+- Issue #1100562: Fix deep-copying of objects derived from the list and
+ dict types. Patch by Michele Orrù and Björn Lindqvist.
+
 - Issue #9753: Fixed socket.dup, which did not always work correctly
 on Windows.
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /