(self)
| 5140 | |
| 5141 | |
| 5142 | def test_post_init(self): |
| 5143 | @dataclass |
| 5144 | class A: |
| 5145 | a: int |
| 5146 | _: KW_ONLY |
| 5147 | b: InitVar[int] |
| 5148 | c: int |
| 5149 | d: InitVar[int] |
| 5150 | def __post_init__(self, b, d): |
| 5151 | raise CustomError(f'{b=} {d=}') |
| 5152 | with self.assertRaisesRegex(CustomError, 'b=3 d=4'): |
| 5153 | A(1, c=2, b=3, d=4) |
| 5154 | |
| 5155 | @dataclass |
| 5156 | class B: |
| 5157 | a: int |
| 5158 | _: KW_ONLY |
| 5159 | b: InitVar[int] |
| 5160 | c: int |
| 5161 | d: InitVar[int] |
| 5162 | def __post_init__(self, b, d): |
| 5163 | self.a = b |
| 5164 | self.c = d |
| 5165 | b = B(1, c=2, b=3, d=4) |
| 5166 | self.assertEqual(asdict(b), {'a': 3, 'c': 4}) |
| 5167 | |
| 5168 | def test_defaults(self): |
| 5169 | # For kwargs, make sure we can have defaults after non-defaults. |
nothing calls this directly
no test coverage detected