Skip to content
19 changes: 19 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4091,6 +4091,25 @@ def method(self) -> None: ...
self.assertIsInstance(Foo(), ProtocolWithMixedMembers)
self.assertNotIsInstance(42, ProtocolWithMixedMembers)

def test_protocol_issubclass_error_message(self):
class Vec2D(Protocol):
x: float
y: float

def square_norm(self) -> float:
return self.x ** 2 + self.y ** 2

assert Vec2D.__protocol_attrs__ == {'x', 'y', 'square_norm'}
expected_error_message = (
"Protocols with non-method members don't support issubclass()."
" Non-method members: {'x', 'y'}."
)

try:
issubclass(int, Vec2D)
except TypeError as exc:
self.assertEqual(str(exc), expected_error_message)


class GenericTests(BaseTestCase):

Expand Down