(cherry picked from commit
a22d05f04c074dbb4f71e7837f54c0bb693db75d)
Co-authored-by: Aviel Boag <avboag@gmail.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Carl Meyer <carl@oddbird.net>
def _get_slots(cls):
match cls.__dict__.get('__slots__'):
+ # A class which does not define __slots__ at all is equivalent
+ # to a class defining __slots__ = ('__dict__', '__weakref__')
case None:
- return
+ yield from ('__dict__', '__weakref__')
case str(slot):
yield slot
# Slots may be any iterable, but we cannot handle an iterator
self.assertIs(a.__weakref__, a_ref)
+ def test_dataclass_derived_weakref_slot(self):
+ class A:
+ pass
+
+ @dataclass(slots=True, weakref_slot=True)
+ class B(A):
+ pass
+
+ B()
+
+
class TestDescriptors(unittest.TestCase):
def test_set_name(self):
# See bpo-33141.
--- /dev/null
+Fixed ``_get_slots`` bug which caused error when defining dataclasses with slots and a weakref_slot.