`typing.Protocol` is explicitly treated as not a `type`
オープン
まだ誰も着手していません。
bug
topic-protocols
topic-runtime-semantics
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
At runtime, isinstance(typing.Protocol, type) is True. When type checking, mypy appears to special-case Protocol:
- mypy:
<typing special form> - Pylance/Pyright:
(class) Protocol
To Reproduce
from typing import Protocol
class A(Protocol): pass
assert Protocol in A.__bases__
bases: tuple[type, ...] = (Protocol, *A.__bases__)
Expected Behavior
Same as Pyright, Protocol is a class (type), no errors.
Actual Behavior
main.py:5: error: Non-overlapping container check (element type: "<typing special form>", container item type: "type") [comparison-overlap]
main.py:6: error: Argument 1 to <tuple> has incompatible type "<typing special form>"; expected "type" [arg-type]
Your Environment
- Mypy version used: 1.0.0, 1.10.1, 1.20.2, 2.3.1
- Mypy command-line flags:
--strict - Python version used: 3.6 - 3.14
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Python 再現コードを mypy --strict で実行することから始め、診断結果を記載されている Pyright の動作と比較します。mypy における typing.Protocol の特別な扱いを特定し、Protocol が型として受け入れられ、再現コードでエラーが発生しないように、テストを追加するかカバレッジを更新します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 52/100