[3.11] gh-102069: Fix __weakref__ descriptor generation for custom dataclasses (GH-102075) (#102662)

gh-102069: Fix `__weakref__` descriptor generation for custom dataclasses (GH-102075)
(cherry picked from commit d97757f793)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2023-03-13 15:17:46 -07:00 committed by GitHub
parent a4fcd06c50
commit b0e221cfc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View file

@ -1175,6 +1175,9 @@ def _add_slots(cls, is_frozen, weakref_slot):
# Remove __dict__ itself.
cls_dict.pop('__dict__', None)
# Clear existing `__weakref__` descriptor, it belongs to a previous type:
cls_dict.pop('__weakref__', None) # gh-102069
# And finally create the class.
qualname = getattr(cls, '__qualname__', None)
cls = type(cls)(cls.__name__, cls.__bases__, cls_dict)