Skip to content

Commit e414d29

Browse files
committed
Stop calling _clear_type_descriptors
1 parent 61230e2 commit e414d29

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/dataclasses.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,6 @@ def _add_slots(cls, is_frozen, weakref_slot, defined_fields):
12831283
if '__slots__' in cls.__dict__:
12841284
raise TypeError(f'{cls.__name__} already specifies __slots__')
12851285

1286-
# gh-102069: Remove existing __weakref__ descriptor.
1287-
# gh-135228: Make sure the original class can be garbage collected.
1288-
sys._clear_type_descriptors(cls)
1289-
12901286
# Create a new dict for our new class.
12911287
cls_dict = dict(cls.__dict__)
12921288
field_names = tuple(f.name for f in fields(cls))
@@ -1304,6 +1300,11 @@ def _add_slots(cls, is_frozen, weakref_slot, defined_fields):
13041300
# available in _MARKER.
13051301
cls_dict.pop(field_name, None)
13061302

1303+
# Remove __dict__ and `__weakref__` descriptors.
1304+
# They'll be added back if applicable.
1305+
cls_dict.pop('__dict__', None)
1306+
cls_dict.pop('__weakref__', None) # gh-102069
1307+
13071308
# And finally create the class.
13081309
qualname = getattr(cls, '__qualname__', None)
13091310
newcls = type(cls)(cls.__name__, cls.__bases__, cls_dict)

0 commit comments

Comments
 (0)