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-145688: Fix _get_protocol_attrs matching user classes named "Protocol" or "Generic"#145724

Open
mvanhorn wants to merge 1 commit intopython:mainfrom
mvanhorn:osc/145688-fix-protocol-name-check
Open

gh-145688: Fix _get_protocol_attrs matching user classes named "Protocol" or "Generic"#145724
mvanhorn wants to merge 1 commit intopython:mainfrom
mvanhorn:osc/145688-fix-protocol-name-check

Conversation

@mvanhorn
Copy link

@mvanhornmvanhorn commentedMar 10, 2026
edited by bedevere-appbot
Loading

Fixes#145688

Summary

_get_protocol_attrs() usedbase.__name__ in {'Protocol', 'Generic'} to skip the basetyping classes when collecting protocol members. This also matched user-defined Protocol subclasses that happened to share those names, causingget_protocol_members() and__protocol_attrs__ to return empty results.

Fix: Changed the check to also verifybase.__module__ == 'typing', so only the actualtyping.Protocol andtyping.Generic are skipped.

Note: A pure identity check (base is Protocol) was considered but doesn't work because_get_protocol_attrs is called during module initialization beforeProtocol is defined.

Test plan

  • Addedtest_get_protocol_members_named_protocol_or_generic covering both "Protocol" and "Generic" named subclasses
  • All 709test_typing tests pass
  • NEWS entry added

This contribution was developed with AI assistance (Claude Code).

…"Protocol" or "Generic"The `_get_protocol_attrs` function used `base.__name__ in {'Protocol', 'Generic'}`to skip the base typing classes, which also skipped user-defined Protocolsubclasses that happened to be named "Protocol" or "Generic". This caused`get_protocol_members()` and `__protocol_attrs__` to return empty resultsfor such classes.Changed to check both `__name__` and `__module__` to ensure only the actual`typing.Protocol` and `typing.Generic` classes are skipped.Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JelleZijlstraJelleZijlstraAwaiting requested review from JelleZijlstraJelleZijlstra is a code owner

@AlexWaygoodAlexWaygoodAwaiting requested review from AlexWaygoodAlexWaygood is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Protocol named "Protocol" or "Generic" has no members.

1 participant

@mvanhorn

[8]ページ先頭

©2009-2026 Movatter.jp