Skip to content

Commit 943a10f

Browse files
committed
Remove special case for tuple and frozensets
1 parent f317c1b commit 943a10f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Lib/copy.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ def deepcopy(x, memo=None, _nil=[]):
123123

124124
cls = type(x)
125125

126-
if cls in _atomic_types or (cls in _immutable_iterables and len(x) == 0):
126+
if cls in _atomic_types:
127127
return x
128128

129129
if memo is None:
130-
if cls in _mutable_iterables and len(x) == 0:
130+
if cls in _builtin_iterables and len(x) == 0:
131131
return cls()
132132
d = id(x)
133133
memo = {}
@@ -137,7 +137,7 @@ def deepcopy(x, memo=None, _nil=[]):
137137
if y is not _nil:
138138
return y
139139

140-
if cls in _mutable_iterables and len(x) == 0:
140+
if cls in _builtin_iterables and len(x) == 0:
141141
y = cls()
142142
elif copier := _deepcopy_dispatch.get(cls):
143143
y = copier(x, memo)
@@ -177,8 +177,7 @@ def deepcopy(x, memo=None, _nil=[]):
177177
_atomic_types = {types.NoneType, types.EllipsisType, types.NotImplementedType,
178178
int, float, bool, complex, bytes, str, types.CodeType, type, range,
179179
types.BuiltinFunctionType, types.FunctionType, weakref.ref, property}
180-
_mutable_iterables = {list, dict, set}
181-
_immutable_iterables = {tuple, frozenset}
180+
_builtin_iterables = {tuple, list, dict, set, frozenset}
182181

183182
_deepcopy_dispatch = d = {}
184183

0 commit comments

Comments
 (0)