MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_no_instantiation

Method test_no_instantiation

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

Source from the content-addressed store, hash-verified

2978 self.assertEqual(typing.get_protocol_members(NewGeneric), {'z'})
2979
2980 def test_no_instantiation(self):
2981 class P(Protocol): pass
2982
2983 with self.assertRaises(TypeError):
2984 P()
2985
2986 class C(P): pass
2987
2988 self.assertIsInstance(C(), C)
2989 with self.assertRaises(TypeError):
2990 C(42)
2991
2992 T = TypeVar('T')
2993
2994 class PG(Protocol[T]): pass
2995
2996 with self.assertRaises(TypeError):
2997 PG()
2998 with self.assertRaises(TypeError):
2999 PG[int]()
3000 with self.assertRaises(TypeError):
3001 PG[T]()
3002
3003 class CG(PG[T]): pass
3004
3005 self.assertIsInstance(CG[int](), CG)
3006 with self.assertRaises(TypeError):
3007 CG[int](42)
3008
3009 def test_protocol_defining_init_does_not_get_overridden(self):
3010 # check that P.__init__ doesn't get clobbered

Callers

nothing calls this directly

Calls 6

TypeVarClass · 0.85
PGClass · 0.85
assertIsInstanceMethod · 0.80
PClass · 0.70
CClass · 0.70
assertRaisesMethod · 0.45

Tested by

no test coverage detected