(self)
| 3962 | self.assertEqual(CorrectSuper.args, ["default", "default"]) |
| 3963 | |
| 3964 | def test_original_class_is_gced(self): |
| 3965 | # gh-135228: Make sure when we replace the class with slots=True, the original class |
| 3966 | # gets garbage collected. |
| 3967 | def make_simple(): |
| 3968 | @dataclass(slots=True) |
| 3969 | class SlotsTest: |
| 3970 | pass |
| 3971 | |
| 3972 | return SlotsTest |
| 3973 | |
| 3974 | def make_with_annotations(): |
| 3975 | @dataclass(slots=True) |
| 3976 | class SlotsTest: |
| 3977 | x: int |
| 3978 | |
| 3979 | return SlotsTest |
| 3980 | |
| 3981 | def make_with_annotations_and_method(): |
| 3982 | @dataclass(slots=True) |
| 3983 | class SlotsTest: |
| 3984 | x: int |
| 3985 | |
| 3986 | def method(self) -> int: |
| 3987 | return self.x |
| 3988 | |
| 3989 | return SlotsTest |
| 3990 | |
| 3991 | def make_with_forwardref(): |
| 3992 | @dataclass(slots=True) |
| 3993 | class SlotsTest: |
| 3994 | x: undefined |
| 3995 | y: list[undefined] |
| 3996 | |
| 3997 | return SlotsTest |
| 3998 | |
| 3999 | for make in (make_simple, make_with_annotations, make_with_annotations_and_method, make_with_forwardref): |
| 4000 | with self.subTest(make=make): |
| 4001 | C = make() |
| 4002 | support.gc_collect() |
| 4003 | candidates = [cls for cls in object.__subclasses__() if cls.__name__ == 'SlotsTest' |
| 4004 | and cls.__firstlineno__ == make.__code__.co_firstlineno + 1] |
| 4005 | self.assertEqual(candidates, [C]) |
| 4006 | |
| 4007 | |
| 4008 | class TestDescriptors(unittest.TestCase): |
nothing calls this directly
no test coverage detected