Request: Optional config to warn when a parameter annotation could use `Mapping` instead of `Dict` or `Sequence` instead of `List`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
- Are you reporting a bug, or opening a feature request?
Feature request
Basically, I think it would be nice if mypy could warn when the user could be giving their function immutable versions of the argument types instead of mutable ones. For example:
def len_greater_than_three(input_list: List[int]) -> bool: # Warning: Could use read only type Sequence instead of List for parameter 1.
return len(input_list) > 3
Being prompted to use immutable types when you're not mutating the input could improve the usability of mypy quite a bit since it would result in functions who's parameters are covariant much more often. It's also convenient to know when a function isn't mutating its arguments based on its annotation, and the desire to default to using immutable types wherever possible probably makes sense for a lot of users.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず issue #8484 と、mypy における既存の診断および設定の慣例を確認します。ミュータブルな型が注釈されたパラメーターに対するオプションの警告動作を定義し、次に、パラメーターが変更されていない場合にのみ例が報告されることと、その設定を構成可能であることを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100