Protocol named "Protocol" or "Generic" has no members.
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
If a protocol is named Protocol or Generic then it will ignore any defined members.
when you get lazy with naming in your unit tests this makes for quite a head scratcher...
Minimal Reproduction
import typing
class Protocol(typing.Protocol):
a: int
members = typing.get_protocol_members(Protocol)
assert members == {"a"}, f"Expected members to be {{'a'}}, got {members}"
Output:
Traceback (most recent call last):
File ".../test_protocol.py", line 10, in <module>
assert members == {"a"}, f"Expected members to be {{'a'}}, got {members}"
^^^^^^^^^^^^^^^^
AssertionError: Expected members to be {'a'}, got frozenset()
Expected Output:
Nothing, script should succeed without error.
Investigation
The problem appears to stem from the _get_protocol_attrs function used by _ProtocolMeta which is defined as follows:
The if statement on line 1887 is too loose in what it matches.
Possibile Fix
The check for base needs to be more specific, either using the instance itself:
if base in {Protocol, Generic}:
continue
or checking the module too, in order to ensure its the correct class being excluded:
if base.__name__ in {'Protocol', 'Generic'} and base.__module__ == 'typing':
continue
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-145724
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
レポートで特定されている関数 _get_protocol_attrs のある Lib/typing.py から始め、提供された最小再現を Python 3.14 で実行します。ユーザー定義クラス Protocol または Generic が、宣言されたプロトコルメンバーを typing.get_protocol_members を通じて公開すれば完了です。開始前に gh-145724 を確認してください。この issue には既存の pull request へのリンクがあります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100