summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authorBluenix <bluenixdev@gmail.com>2022-06-08 00:53:08 (GMT)
committerGitHub <noreply@github.com>2022-06-08 00:53:08 (GMT)
commit5849af7a80166e9e82040e082f22772bd7cf3061 (patch)
treefa94a6b81bbdf006040f1275942a40cb91918b4c /Lib/dataclasses.py
parentffc58a9710172b2d716a810a9f303828f3ebf108 (diff)
downloadcpython-5849af7a80166e9e82040e082f22772bd7cf3061.zip
cpython-5849af7a80166e9e82040e082f22772bd7cf3061.tar.gz
cpython-5849af7a80166e9e82040e082f22772bd7cf3061.tar.bz2
GH-93521: For dataclasses, filter out `__weakref__` slot if present in bases (GH-93535)
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 4645ebf..18ab690 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -1156,11 +1156,16 @@ def _add_slots(cls, is_frozen, weakref_slot):
itertools.chain.from_iterable(map(_get_slots, cls.__mro__[1:-1]))
)
# The slots for our class. Remove slots from our base classes. Add
- # '__weakref__' if weakref_slot was given.
+ # '__weakref__' if weakref_slot was given, unless it is already present.
cls_dict["__slots__"] = tuple(
- itertools.chain(
- itertools.filterfalse(inherited_slots.__contains__, field_names),
- ("__weakref__",) if weakref_slot else ())
+ itertools.filterfalse(
+ inherited_slots.__contains__,
+ itertools.chain(
+ # gh-93521: '__weakref__' also needs to be filtered out if
+ # already present in inherited_slots
+ field_names, ('__weakref__',) if weakref_slot else ()
+ )
+ ),
)
for field_name in field_names: