8000 gh-112345: Let failed protocol subclasscheck show non-method members by randolf-scholz · Pull Request #112344 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112345: Let failed protocol subclasscheck show non-method members #112344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 24, 2023
Prev Previous commit
Next Next commit
added test
  • Loading branch information
randolf-scholz committed Nov 23, 2023
commit fd840b28acd7f64712e4c025bc1b2b5f07c58431
19 changes: 19 additions & 0 deletions Lib/test/test_typing.py
View file Open in desktop
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
0