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

Method test_no_inheritance_from_nominal

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

Source from the content-addressed store, hash-verified

2942 self.assertIsInstance(f, HasCallProtocol)
2943
2944 def test_no_inheritance_from_nominal(self):
2945 class C: pass
2946
2947 class BP(Protocol): pass
2948
2949 with self.assertRaises(TypeError):
2950 class P(C, Protocol):
2951 pass
2952 with self.assertRaises(TypeError):
2953 class Q(Protocol, C):
2954 pass
2955 with self.assertRaises(TypeError):
2956 class R(BP, C, Protocol):
2957 pass
2958
2959 class D(BP, C): pass
2960
2961 class E(C, BP): pass
2962
2963 self.assertNotIsInstance(D(), E)
2964 self.assertNotIsInstance(E(), D)
2965
2966 def test_inheritance_from_object(self):
2967 # Inheritance from object is specifically allowed, unlike other nominal classes

Callers

nothing calls this directly

Calls 4

assertNotIsInstanceMethod · 0.80
DClass · 0.70
EClass · 0.70
assertRaisesMethod · 0.45

Tested by

no test coverage detected