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

Method test_cannot_instantiate_abstract

Lib/test/test_typing.py:3038–3054  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3036 self.assertEqual(c.x, 1)
3037
3038 def test_cannot_instantiate_abstract(self):
3039 @runtime_checkable
3040 class P(Protocol):
3041 @abc.abstractmethod
3042 def ameth(self) -> int:
3043 raise NotImplementedError
3044
3045 class B(P):
3046 pass
3047
3048 class C(B):
3049 def ameth(self) -> int:
3050 return 26
3051
3052 with self.assertRaises(TypeError):
3053 B()
3054 self.assertIsInstance(C(), P)
3055
3056 def test_subprotocols_extending(self):
3057 class P1(Protocol):

Callers

nothing calls this directly

Calls 4

assertIsInstanceMethod · 0.80
BClass · 0.70
CClass · 0.70
assertRaisesMethod · 0.45

Tested by

no test coverage detected