(self)
| 4425 | Foo() # Previously triggered RecursionError |
| 4426 | |
| 4427 | def test_get_protocol_members(self): |
| 4428 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4429 | get_protocol_members(object) |
| 4430 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4431 | get_protocol_members(object()) |
| 4432 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4433 | get_protocol_members(Protocol) |
| 4434 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4435 | get_protocol_members(Generic) |
| 4436 | |
| 4437 | class P(Protocol): |
| 4438 | a: int |
| 4439 | def b(self) -> str: ... |
| 4440 | @property |
| 4441 | def c(self) -> int: ... |
| 4442 | |
| 4443 | self.assertEqual(get_protocol_members(P), {'a', 'b', 'c'}) |
| 4444 | self.assertIsInstance(get_protocol_members(P), frozenset) |
| 4445 | self.assertIsNot(get_protocol_members(P), P.__protocol_attrs__) |
| 4446 | |
| 4447 | class Concrete: |
| 4448 | a: int |
| 4449 | def b(self) -> str: return "capybara" |
| 4450 | @property |
| 4451 | def c(self) -> int: return 5 |
| 4452 | |
| 4453 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4454 | get_protocol_members(Concrete) |
| 4455 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4456 | get_protocol_members(Concrete()) |
| 4457 | |
| 4458 | class ConcreteInherit(P): |
| 4459 | a: int = 42 |
| 4460 | def b(self) -> str: return "capybara" |
| 4461 | @property |
| 4462 | def c(self) -> int: return 5 |
| 4463 | |
| 4464 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4465 | get_protocol_members(ConcreteInherit) |
| 4466 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4467 | get_protocol_members(ConcreteInherit()) |
| 4468 | |
| 4469 | def test_is_protocol(self): |
| 4470 | self.assertTrue(is_protocol(Proto)) |
nothing calls this directly
no test coverage detected