]> granicus.if.org Git - python/commitdiff
Issue #26202: copy.deepcopy() now correctly copies range() objects with
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 28 Jan 2016 19:43:35 +0000 (21:43 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 28 Jan 2016 19:43:35 +0000 (21:43 +0200)
non-atomic attributes.

Lib/copy.py
Lib/test/test_copy.py
Misc/NEWS

index 493c487d8a82b14ef655158d9b1315c8d795212e..972b94ab491f158703e1277254d78c17a9e3b0f6 100644 (file)
@@ -207,7 +207,6 @@ try:
 except AttributeError:
     pass
 d[type] = _deepcopy_atomic
-d[range] = _deepcopy_atomic
 d[types.BuiltinFunctionType] = _deepcopy_atomic
 d[types.FunctionType] = _deepcopy_atomic
 d[weakref.ref] = _deepcopy_atomic
index 4107e8afd62911ec6dce09eef8f06642f29aa1d7..7912c7cd692d8e827feb5c0752a7c385385a79f8 100644 (file)
@@ -314,7 +314,7 @@ class TestCopy(unittest.TestCase):
             pass
         tests = [None, 42, 2**100, 3.14, True, False, 1j,
                  "hello", "hello\u1234", f.__code__,
-                 NewStyle, range(10), Classic, max]
+                 NewStyle, Classic, max]
         for x in tests:
             self.assertIs(copy.deepcopy(x), x)
 
@@ -536,6 +536,17 @@ class TestCopy(unittest.TestCase):
         self.assertIsNot(y, x)
         self.assertIs(y.foo, y)
 
+    def test_deepcopy_range(self):
+        class I(int):
+            pass
+        x = range(I(10))
+        y = copy.deepcopy(x)
+        self.assertIsNot(y, x)
+        self.assertEqual(y, x)
+        self.assertIsNot(y.stop, x.stop)
+        self.assertEqual(y.stop, x.stop)
+        self.assertIsInstance(y.stop, I)
+
     # _reconstruct()
 
     def test_reconstruct_string(self):
index cd693fc93c91b672be056481c4dc7cd6d12d63a0..cbfae9bdf3b4769837336ce6e5be05f4aa8b0217 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #26202: copy.deepcopy() now correctly copies range() objects with
+  non-atomic attributes.
+
 - Issue #19883: Fixed possible integer overflows in zipimport.
 
 - Issue #26227: On Windows, getnameinfo(), gethostbyaddr() and