(self)
| 4533 | Foo() # Previously triggered RecursionError |
| 4534 | |
| 4535 | def test_get_protocol_members(self): |
| 4536 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4537 | get_protocol_members(object) |
| 4538 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4539 | get_protocol_members(object()) |
| 4540 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4541 | get_protocol_members(Protocol) |
| 4542 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4543 | get_protocol_members(Generic) |
| 4544 | |
| 4545 | class P(Protocol): |
| 4546 | a: int |
| 4547 | def b(self) -> str: ... |
| 4548 | @property |
| 4549 | def c(self) -> int: ... |
| 4550 | |
| 4551 | self.assertEqual(get_protocol_members(P), {'a', 'b', 'c'}) |
| 4552 | self.assertIsInstance(get_protocol_members(P), frozenset) |
| 4553 | self.assertIsNot(get_protocol_members(P), P.__protocol_attrs__) |
| 4554 | |
| 4555 | class Concrete: |
| 4556 | a: int |
| 4557 | def b(self) -> str: return "capybara" |
| 4558 | @property |
| 4559 | def c(self) -> int: return 5 |
| 4560 | |
| 4561 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4562 | get_protocol_members(Concrete) |
| 4563 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4564 | get_protocol_members(Concrete()) |
| 4565 | |
| 4566 | class ConcreteInherit(P): |
| 4567 | a: int = 42 |
| 4568 | def b(self) -> str: return "capybara" |
| 4569 | @property |
| 4570 | def c(self) -> int: return 5 |
| 4571 | |
| 4572 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4573 | get_protocol_members(ConcreteInherit) |
| 4574 | with self.assertRaisesRegex(TypeError, "not a Protocol"): |
| 4575 | get_protocol_members(ConcreteInherit()) |
| 4576 | |
| 4577 | def test_is_protocol(self): |
| 4578 | self.assertTrue(is_protocol(Proto)) |
nothing calls this directly
no test coverage detected