Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a20bbf

Browse files
Issue #26202: copy.deepcopy() now correctly copies range() objects with
non-atomic attributes.
1 parent d5db573 commit 0a20bbf

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

Lib/copy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ def _deepcopy_atomic(x, memo):
207207
except AttributeError:
208208
pass
209209
d[type] = _deepcopy_atomic
210-
d[range] = _deepcopy_atomic
211210
d[types.BuiltinFunctionType] = _deepcopy_atomic
212211
d[types.FunctionType] = _deepcopy_atomic
213212
d[weakref.ref] = _deepcopy_atomic

Lib/test/test_copy.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def f():
314314
pass
315315
tests = [None, 42, 2**100, 3.14, True, False, 1j,
316316
"hello", "hello\u1234", f.__code__,
317-
NewStyle, range(10), Classic, max]
317+
NewStyle, Classic, max]
318318
for x in tests:
319319
self.assertIs(copy.deepcopy(x), x)
320320

@@ -536,6 +536,17 @@ class C:
536536
self.assertIsNot(y, x)
537537
self.assertIs(y.foo, y)
538538

539+
def test_deepcopy_range(self):
540+
class I(int):
541+
pass
542+
x = range(I(10))
543+
y = copy.deepcopy(x)
544+
self.assertIsNot(y, x)
545+
self.assertEqual(y, x)
546+
self.assertIsNot(y.stop, x.stop)
547+
self.assertEqual(y.stop, x.stop)
548+
self.assertIsInstance(y.stop, I)
549+
539550
# _reconstruct()
540551

541552
def test_reconstruct_string(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ Core and Builtins
6666
Library
6767
-------
6868

69+
- Issue #26202: copy.deepcopy() now correctly copies range() objects with
70+
non-atomic attributes.
71+
6972
- Issue #19883: Fixed possible integer overflows in zipimport.
7073

7174
- Issue #26227: On Windows, getnameinfo(), gethostbyaddr() and

0 commit comments

Comments
 (0)