Skip to content

Commit a8ab7dd

Browse files
authored
Merge pull request RustPython#5175 from Blues-star/copy
Update `copy.py` and `test_copy.py` from CPython v3.12
2 parents 7c722c2 + 83b8c3a commit a8ab7dd

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

Lib/copy.py

+8-20
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ class Error(Exception):
5656
pass
5757
error = Error # backward compatibility
5858

59-
try:
60-
from org.python.core import PyStringMap
61-
except ImportError:
62-
PyStringMap = None
63-
6459
__all__ = ["Error", "copy", "deepcopy"]
6560

6661
def copy(x):
@@ -106,23 +101,18 @@ def copy(x):
106101

107102
def _copy_immutable(x):
108103
return x
109-
for t in (type(None), int, float, bool, complex, str, tuple,
104+
for t in (types.NoneType, int, float, bool, complex, str, tuple,
110105
bytes, frozenset, type, range, slice, property,
111-
types.BuiltinFunctionType, type(Ellipsis), type(NotImplemented),
112-
types.FunctionType, weakref.ref):
113-
d[t] = _copy_immutable
114-
t = getattr(types, "CodeType", None)
115-
if t is not None:
106+
types.BuiltinFunctionType, types.EllipsisType,
107+
types.NotImplementedType, types.FunctionType, types.CodeType,
108+
weakref.ref):
116109
d[t] = _copy_immutable
117110

118111
d[list] = list.copy
119112
d[dict] = dict.copy
120113
d[set] = set.copy
121114
d[bytearray] = bytearray.copy
122115

123-
if PyStringMap is not None:
124-
d[PyStringMap] = PyStringMap.copy
125-
126116
del d, t
127117

128118
def deepcopy(x, memo=None, _nil=[]):
@@ -181,9 +171,9 @@ def deepcopy(x, memo=None, _nil=[]):
181171

182172
def _deepcopy_atomic(x, memo):
183173
return x
184-
d[type(None)] = _deepcopy_atomic
185-
d[type(Ellipsis)] = _deepcopy_atomic
186-
d[type(NotImplemented)] = _deepcopy_atomic
174+
d[types.NoneType] = _deepcopy_atomic
175+
d[types.EllipsisType] = _deepcopy_atomic
176+
d[types.NotImplementedType] = _deepcopy_atomic
187177
d[int] = _deepcopy_atomic
188178
d[float] = _deepcopy_atomic
189179
d[bool] = _deepcopy_atomic
@@ -231,8 +221,6 @@ def _deepcopy_dict(x, memo, deepcopy=deepcopy):
231221
y[deepcopy(key, memo)] = deepcopy(value, memo)
232222
return y
233223
d[dict] = _deepcopy_dict
234-
if PyStringMap is not None:
235-
d[PyStringMap] = _deepcopy_dict
236224

237225
def _deepcopy_method(x, memo): # Copy instance methods
238226
return type(x)(x.__func__, deepcopy(x.__self__, memo))
@@ -301,4 +289,4 @@ def _reconstruct(x, memo, func, args,
301289
y[key] = value
302290
return y
303291

304-
del types, weakref, PyStringMap
292+
del types, weakref

Lib/test/test_copy.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ def __getattribute__(self, name):
9191
# Type-specific _copy_xxx() methods
9292

9393
def test_copy_atomic(self):
94-
class Classic:
95-
pass
96-
class NewStyle(object):
94+
class NewStyle:
9795
pass
9896
def f():
9997
pass
@@ -103,7 +101,7 @@ class WithMetaclass(metaclass=abc.ABCMeta):
103101
42, 2**100, 3.14, True, False, 1j,
104102
"hello", "hello\u1234", f.__code__,
105103
b"world", bytes(range(256)), range(10), slice(1, 10, 2),
106-
NewStyle, Classic, max, WithMetaclass, property()]
104+
NewStyle, max, WithMetaclass, property()]
107105
for x in tests:
108106
self.assertIs(copy.copy(x), x)
109107

@@ -358,15 +356,13 @@ def __getattribute__(self, name):
358356
# Type-specific _deepcopy_xxx() methods
359357

360358
def test_deepcopy_atomic(self):
361-
class Classic:
362-
pass
363-
class NewStyle(object):
359+
class NewStyle:
364360
pass
365361
def f():
366362
pass
367363
tests = [None, ..., NotImplemented, 42, 2**100, 3.14, True, False, 1j,
368364
b"bytes", "hello", "hello\u1234", f.__code__,
369-
NewStyle, range(10), Classic, max, property()]
365+
NewStyle, range(10), max, property()]
370366
for x in tests:
371367
self.assertIs(copy.deepcopy(x), x)
372368

0 commit comments

Comments
 (0)