Add "is invariant" warning to Set as well as List for situations where a Collection should be used
オープン
まだ誰も着手していません。
feature
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Feature
mypy has a lovely warning about List being invariant in situations like this:
ls: List[int] = [1, 2, 3]
def process(stuff: List[Union[int, str]]):
...
process(ls) # type error here, w/ nice explanation of invariance and suggestion to use Sequence
However, it does not have the same warning when Set is used in the same way:
s: Set[int] = {1, 2, 3}
def process(stuff: Set[Union[int, str]]):
...
process(s) # merely states that the type is incompatible, no mention of invariance
Would be nice if the same warning mechanism could trigger here, suggesting Collection.
Pitch
Hopefully this is a simple widening of a rule that's special-cased for lists to get sets too? Not sure if other types like Dict/Tuple might be included too; I haven't tested them. If it's a lot of effort probably not worth it.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、既存の List の不変性に関する警告とそのテストを見つけます。issue では具体的なファイルやエントリポイントは指定されていません。同じ警告の動作を Set に拡張し、例に示されているように、診断メッセージが不変性を説明し、Collection を提案することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100