Optional strict checking of *args and/or multiple assignment
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Currently mypy does optimistic checking of *args -- we don't generate error if it could be valid. This seems like a reasonable default, since it avoids false positive errors. However, some users might prefer stricter checking as an option. When this option is enabled, mypy would only allow variable-length (non-Any) *args in a call if the callee also accepts *args.
Example:
def f(a: int) -> None: pass
x = [1, 2]
f(*x) # Currently accepted, since mypy doesn't know the length of x
PR #7392 relaxed the rules so that we assume that any list *args argument could be empty and thus we don't complain about even if a caller *args argument is only valid when it's empty.
Similarly this option (or a similar option) could reject variable-length rvalues in multiple assignment like this:
x = [1, 2]
a, b, c = x # Currently accepted
If we'd have support for enabling/disabling specific error codes, these checks could easily be implemented through error codes that are disabled by default.
Refactoring code such as the above (if correct) to pass mypy could be somewhat painful, however. It could be written like this:
def f(a: int, b: int) -> None: pass
def g(x: List[int]) -> None:
assert len(x) == 2
f(x[0], x[1])
(Of course, a # type: ignore would also work.)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
ソースファイルやテストは指定されていません。まず PR #7392 と、可変長の *args および複数代入の既存の扱いを確認してください。完了の条件は、これらのケースに対する厳密チェックをオプションで行う設計を決定し、チェックをどのように有効化するかも含めることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100