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

Method test_inherit_from_protocol

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

Source from the content-addressed store, hash-verified

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
2488class TestInitAnnotate(unittest.TestCase):

Callers

nothing calls this directly

Calls 3

CClass · 0.70
DClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected