MCPcopy Index your code
hub / github.com/python/cpython / test_post_init_classmethod

Method test_post_init_classmethod

Lib/test/test_dataclasses/__init__.py:1098–1111  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1096 self.assertTrue(flag)
1097
1098 def test_post_init_classmethod(self):
1099 @dataclass
1100 class C:
1101 flag = False
1102 x: int
1103 y: int
1104 @classmethod
1105 def __post_init__(cls):
1106 cls.flag = True
1107
1108 self.assertFalse(C.flag)
1109 c = C(3, 4)
1110 self.assertEqual((c.x, c.y), (3, 4))
1111 self.assertTrue(C.flag)
1112
1113 def test_post_init_not_auto_added(self):
1114 # See bpo-46757, which had proposed always adding __post_init__. As

Callers

nothing calls this directly

Calls 4

assertFalseMethod · 0.95
assertEqualMethod · 0.95
assertTrueMethod · 0.95
CClass · 0.70

Tested by

no test coverage detected