(self)
| 2465 | self.assertEqual(C(5).x, 10) |
| 2466 | |
| 2467 | def test_inherit_from_protocol(self): |
| 2468 | # Dataclasses inheriting from protocol should preserve their own `__init__`. |
| 2469 | # See bpo-45081. |
| 2470 | |
| 2471 | class P(Protocol): |
| 2472 | a: int |
| 2473 | |
| 2474 | @dataclass |
| 2475 | class C(P): |
| 2476 | a: int |
| 2477 | |
| 2478 | self.assertEqual(C(5).a, 5) |
| 2479 | |
| 2480 | @dataclass |
| 2481 | class D(P): |
| 2482 | def __init__(self, a): |
| 2483 | self.a = a * 2 |
| 2484 | |
| 2485 | self.assertEqual(D(5).a, 10) |
| 2486 | |
| 2487 | |
| 2488 | class TestInitAnnotate(unittest.TestCase): |
nothing calls this directly
no test coverage detected