Skip to content

Commit 4bf23e6

Browse files
committed
pythongh-123935: Fix typo in _get_slots in dataclasses.py
1 parent 00ffdf2 commit 4bf23e6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Lib/dataclasses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ def _get_slots(cls):
12081208
slots = []
12091209
if getattr(cls, '__weakrefoffset__', -1) != 0:
12101210
slots.append('__weakref__')
1211-
if getattr(cls, '__dictrefoffset__', -1) != 0:
1211+
if getattr(cls, '__dictoffset__', -1) != 0:
12121212
slots.append('__dict__')
12131213
yield from slots
12141214
case str(slot):

Lib/test/test_dataclasses/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -3664,6 +3664,23 @@ class A(WithDictSlot): ...
36643664
self.assertEqual(A().__dict__, {})
36653665
A()
36663666

3667+
@support.cpython_only
3668+
def test_dataclass_slot_dict_ctype(self):
3669+
# https://github.com/python/cpython/issues/123935
3670+
from test.support import import_helper
3671+
# Skips test if `_testcapi` is not present:
3672+
_testcapi = import_helper.import_module('_testcapi')
3673+
3674+
@dataclass(slots=True)
3675+
class A(_testcapi.HeapCTypeWithDict):
3676+
__dict__: dict = {}
3677+
self.assertEqual(A.__slots__, ())
3678+
3679+
@dataclass(slots=True)
3680+
class A(_testcapi.HeapCTypeWithWeakref):
3681+
__dict__: dict = {}
3682+
self.assertEqual(A.__slots__, ('__dict__',))
3683+
36673684
@support.cpython_only
36683685
def test_slots_with_wrong_init_subclass(self):
36693686
# TODO: This test is for a kinda-buggy behavior.

0 commit comments

Comments
 (0)