@@ -75,24 +75,20 @@ def copy(x):
75
75
if copier :
76
76
return copier (x )
77
77
78
- try :
79
- issc = issubclass (cls , type )
80
- except TypeError : # cls is not a class
81
- issc = False
82
- if issc :
78
+ if issubclass (cls , type ):
83
79
# treat it as a regular class:
84
80
return _copy_immutable (x )
85
81
86
82
copier = getattr (cls , "__copy__" , None )
87
- if copier :
83
+ if copier is not None :
88
84
return copier (x )
89
85
90
86
reductor = dispatch_table .get (cls )
91
- if reductor :
87
+ if reductor is not None :
92
88
rv = reductor (x )
93
89
else :
94
90
reductor = getattr (x , "__reduce_ex__" , None )
95
- if reductor :
91
+ if reductor is not None :
96
92
rv = reductor (4 )
97
93
else :
98
94
reductor = getattr (x , "__reduce__" , None )
@@ -146,26 +142,22 @@ def deepcopy(x, memo=None, _nil=[]):
146
142
cls = type (x )
147
143
148
144
copier = _deepcopy_dispatch .get (cls )
149
- if copier :
145
+ if copier is not None :
150
146
y = copier (x , memo )
151
147
else :
152
- try :
153
- issc = issubclass (cls , type )
154
- except TypeError : # cls is not a class (old Boost; see SF #502085)
155
- issc = 0
156
- if issc :
148
+ if issubclass (cls , type ):
157
149
y = _deepcopy_atomic (x , memo )
158
150
else :
159
151
copier = getattr (x , "__deepcopy__" , None )
160
- if copier :
152
+ if copier is not None :
161
153
y = copier (memo )
162
154
else :
163
155
reductor = dispatch_table .get (cls )
164
156
if reductor :
165
157
rv = reductor (x )
166
158
else :
167
159
reductor = getattr (x , "__reduce_ex__" , None )
168
- if reductor :
160
+ if reductor is not None :
169
161
rv = reductor (4 )
170
162
else :
171
163
reductor = getattr (x , "__reduce__" , None )
@@ -198,10 +190,7 @@ def _deepcopy_atomic(x, memo):
198
190
d [complex ] = _deepcopy_atomic
199
191
d [bytes ] = _deepcopy_atomic
200
192
d [str ] = _deepcopy_atomic
201
- try :
202
- d [types .CodeType ] = _deepcopy_atomic
203
- except AttributeError :
204
- pass
193
+ d [types .CodeType ] = _deepcopy_atomic
205
194
d [type ] = _deepcopy_atomic
206
195
d [types .BuiltinFunctionType ] = _deepcopy_atomic
207
196
d [types .FunctionType ] = _deepcopy_atomic
0 commit comments