@@ -67,13 +67,15 @@ def copy(x):
67
67
68
68
cls = type (x )
69
69
70
- copier = _copy_dispatch .get (cls )
71
- if copier :
72
- return copier (x )
70
+ if cls in _copy_atomic_types :
71
+ return x
72
+ if cls in _copy_builtin_containers :
73
+ return cls .copy (x )
74
+
73
75
74
76
if issubclass (cls , type ):
75
77
# treat it as a regular class:
76
- return _copy_immutable ( x )
78
+ return x
77
79
78
80
copier = getattr (cls , "__copy__" , None )
79
81
if copier is not None :
@@ -98,23 +100,12 @@ def copy(x):
98
100
return _reconstruct (x , None , * rv )
99
101
100
102
101
- _copy_dispatch = d = {}
102
-
103
- def _copy_immutable (x ):
104
- return x
105
- for t in (types .NoneType , int , float , bool , complex , str , tuple ,
103
+ _copy_atomic_types = {types .NoneType , int , float , bool , complex , str , tuple ,
106
104
bytes , frozenset , type , range , slice , property ,
107
105
types .BuiltinFunctionType , types .EllipsisType ,
108
106
types .NotImplementedType , types .FunctionType , types .CodeType ,
109
- weakref .ref , super ):
110
- d [t ] = _copy_immutable
111
-
112
- d [list ] = list .copy
113
- d [dict ] = dict .copy
114
- d [set ] = set .copy
115
- d [bytearray ] = bytearray .copy
116
-
117
- del d , t
107
+ weakref .ref , super }
108
+ _copy_builtin_containers = {list , dict , set , bytearray }
118
109
119
110
def deepcopy (x , memo = None , _nil = []):
120
111
"""Deep copy operation on arbitrary Python objects.
0 commit comments