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
use assertRaisesRegex
  • Loading branch information
randolf-scholz committed Nov 23, 2023
commit 5db267099587224c0a4991ee96b79a69849192b6
9 changes: 2 additions & 7 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4099,17 +4099,12 @@ class Vec2D(Protocol):
def square_norm(self) -> float:
return self.x ** 2 + self.y ** 2

self.assertEqual(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)

self.assertRaisesRegex(TypeError, f'^{re.escape(expected_error_message)}$')
self.assertEqual(Vec2D.__protocol_attrs__, {'x', 'y', 'square_norm'})

class GenericTests(BaseTestCase):

Expand Down
0