Skip to content

Commit 36a36b2

Browse files
committed
Update copy.py from CPython v3.12.0
1 parent d061837 commit 36a36b2

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
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

0 commit comments

Comments
 (0)