Suggest making protocol attribute read-only if invariance causes conflict
オープン
まだ誰も着手していません。
good-second-issue
priority-1-normal
topic-protocols
topic-usability
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
If a concrete attribute has a narrower type than protocol attribute, mypy will complain (adapted from #5998):
prog.py:59: error: Argument 1 to "f" has incompatible type "C"; expected "Proto"
prog.py:59: note: Following member(s) of "C" have conflicts:
prog.py:59: note: name: expected "Optional[str]", got "str"
It could help if mypy would suggest making the protocol attribute read-only (property or final attribute), which is often the right thing to do.
We already generate a related suggestion to use a covariant collection type when using an invariant collection causes type incompatibility.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
不変コレクションによって非互換性が発生する場合に共変コレクション型を使用する既存の提案を追うことから始めます。競合するプロトコル属性を読み取り専用にするための対応する提案を追加し、示されている例の回帰カバレッジで診断を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100