@@ -276,11 +276,8 @@ def _replace_bot(cls, obj: object, memo: Dict[int, object]) -> object: # pylint
276276 new_obj [cls ._replace_bot (k , memo )] = cls ._replace_bot (val , memo )
277277 memo [obj_id ] = new_obj
278278 return new_obj
279- if hasattr (obj , '__dict__' ):
280- for attr_name , attr in new_obj .__dict__ .items ():
281- setattr (new_obj , attr_name , cls ._replace_bot (attr , memo ))
282- memo [obj_id ] = new_obj
283- return new_obj
279+ # if '__dict__' in obj.__slots__, we already cover this here, that's why the
280+ # __dict__ case comes below
284281 if hasattr (obj , '__slots__' ):
285282 for attr_name in new_obj .__slots__ :
286283 setattr (
@@ -290,6 +287,11 @@ def _replace_bot(cls, obj: object, memo: Dict[int, object]) -> object: # pylint
290287 )
291288 memo [obj_id ] = new_obj
292289 return new_obj
290+ if hasattr (obj , '__dict__' ):
291+ for attr_name , attr in new_obj .__dict__ .items ():
292+ setattr (new_obj , attr_name , cls ._replace_bot (attr , memo ))
293+ memo [obj_id ] = new_obj
294+ return new_obj
293295
294296 return obj
295297
@@ -364,11 +366,8 @@ def _insert_bot(self, obj: object, memo: Dict[int, object]) -> object: # pylint
364366 new_obj [self ._insert_bot (k , memo )] = self ._insert_bot (val , memo )
365367 memo [obj_id ] = new_obj
366368 return new_obj
367- if hasattr (obj , '__dict__' ):
368- for attr_name , attr in new_obj .__dict__ .items ():
369- setattr (new_obj , attr_name , self ._insert_bot (attr , memo ))
370- memo [obj_id ] = new_obj
371- return new_obj
369+ # if '__dict__' in obj.__slots__, we already cover this here, that's why the
370+ # __dict__ case comes below
372371 if hasattr (obj , '__slots__' ):
373372 for attr_name in obj .__slots__ :
374373 setattr (
@@ -378,6 +377,11 @@ def _insert_bot(self, obj: object, memo: Dict[int, object]) -> object: # pylint
378377 )
379378 memo [obj_id ] = new_obj
380379 return new_obj
380+ if hasattr (obj , '__dict__' ):
381+ for attr_name , attr in new_obj .__dict__ .items ():
382+ setattr (new_obj , attr_name , self ._insert_bot (attr , memo ))
383+ memo [obj_id ] = new_obj
384+ return new_obj
381385
382386 return obj
383387
0 commit comments