Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
AlexWaygood merged 11 commits intopython:mainfromrandolf-scholz:protocol_error_mesage
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
sort members, fixed unit test
  • Loading branch information
@randolf-scholz
randolf-scholz committedNov 23, 2023
commit998b45e6abc57d4b361a3b4d6cb8645dabd4b8fa
4 changes: 2 additions & 2 deletionsLib/test/test_typing.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4099,14 +4099,14 @@ 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'}."
" Non-method members:['x', 'y']."
)
with self.assertRaisesRegex(TypeError, re.escape(expected_error_message)):
issubclass(int, Vec2D)

self.assertEqual(Vec2D.__protocol_attrs__, {'x', 'y', 'square_norm'})

class GenericTests(BaseTestCase):

Expand Down
4 changes: 2 additions & 2 deletionsLib/typing.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1828,10 +1828,10 @@ def __subclasscheck__(cls, other):
not cls.__callable_proto_members_only__
and cls.__dict__.get("__subclasshook__") is _proto_hook
):
non_method_attrs ={
non_method_attrs =sorted(
attr for attr in cls.__protocol_attrs__
if not callable(getattr(cls, attr, None))
}
)
raise TypeError(
"Protocols with non-method members don't support issubclass()."
f" Non-method members: {non_method_attrs}."
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp