Skip to content

Commit 883363f

Browse files
Move tests to other case
1 parent bff566a commit 883363f

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

Lib/test/test_dataclasses/__init__.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,33 @@ class C:
34053405
c = C('hello')
34063406
self.assertEqual(deepcopy(c), c)
34073407

3408+
def test_slotted_set_del_attr_reference_new_class_via__class__(self):
3409+
# See https://github.com/python/cpython/pull/144021
3410+
@dataclass(frozen=True, slots=True)
3411+
class SetDelAttrTest:
3412+
pass
3413+
3414+
for method_name in ('__setattr__', '__delattr__'):
3415+
with self.subTest(method_name=method_name):
3416+
method = getattr(SetDelAttrTest, method_name)
3417+
cell_idx = method.__code__.co_freevars.index('__class__')
3418+
reference = method.__closure__[cell_idx].cell_contents
3419+
self.assertIs(reference, SetDelAttrTest)
3420+
3421+
def test_slotted_set_del_attr_do_not_reference_old_class(self):
3422+
# See https://github.com/python/cpython/pull/144021
3423+
class SetDelAttrTest:
3424+
pass
3425+
3426+
OriginalCls = SetDelAttrTest
3427+
SetDelAttrTest = dataclass(frozen=True, slots=True)(SetDelAttrTest)
3428+
3429+
for method_name in ('__setattr__', '__delattr__'):
3430+
with self.subTest(method_name=method_name):
3431+
method = getattr(SetDelAttrTest, method_name)
3432+
cell_contents = [cell.cell_contents for cell in method.__closure__]
3433+
self.assertNotIn(OriginalCls, cell_contents)
3434+
34083435

34093436
class TestSlots(unittest.TestCase):
34103437
def test_simple(self):
@@ -3971,6 +3998,7 @@ class SlotsTest:
39713998

39723999
return SlotsTest
39734000

4001+
# See https://github.com/python/cpython/issues/135228#issuecomment-3755979059
39744002
def make_frozen():
39754003
@dataclass(frozen=True, slots=True)
39764004
class SlotsTest:
@@ -4011,31 +4039,6 @@ class SlotsTest:
40114039
and cls.__firstlineno__ == make.__code__.co_firstlineno + 1]
40124040
self.assertEqual(candidates, [C])
40134041

4014-
def test_set_del_attr_reference_new_class_via__class__(self):
4015-
@dataclass(frozen=True, slots=True)
4016-
class SetDelAttrTest:
4017-
pass
4018-
4019-
for method_name in ('__setattr__', '__delattr__'):
4020-
with self.subTest(method_name=method_name):
4021-
method = getattr(SetDelAttrTest, method_name)
4022-
cell_idx = method.__code__.co_freevars.index('__class__')
4023-
reference = method.__closure__[cell_idx].cell_contents
4024-
self.assertIs(reference, SetDelAttrTest)
4025-
4026-
def test_set_del_attr_do_not_reference_old_class(self):
4027-
class SetDelAttrTest:
4028-
pass
4029-
4030-
OriginalCls = SetDelAttrTest
4031-
SetDelAttrTest = dataclass(frozen=True, slots=True)(SetDelAttrTest)
4032-
4033-
for method_name in ('__setattr__', '__delattr__'):
4034-
with self.subTest(method_name=method_name):
4035-
method = getattr(SetDelAttrTest, method_name)
4036-
cell_contents = [cell.cell_contents for cell in method.__closure__]
4037-
self.assertNotIn(OriginalCls, cell_contents)
4038-
40394042

40404043
class TestDescriptors(unittest.TestCase):
40414044
def test_set_name(self):

0 commit comments

Comments
 (0)