Redefinition of function arguments can give unclear error message
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
With
import typing
# simulate an untyped module function
def function() -> typing.Any:
return []
def foo(var: list|str) -> list:
# insert a lot of code so that it's totally unobvious that "var" is a function parameter
var = function()
return var
You get the output
$ mypy ./test2.py
test2.py:8: error: Incompatible return value type (got "list[Any] | str", expected "list[Any]") [return-value]
Found 1 error in 1 file (checked 1 source file)
$ mypy--version
mypy 1.10.0 (compiled: yes)
which is technically correct, as var was defined as list[Any] | str as a parameter. But if you don't realise that, say there is a ton of code between where that's defined and where the return value is, you are left looking at var = function(); return var and wondering why the heck function() has been inferred to return list[Any] | str.
For a "standard" redefinition a [no-redef] warning comes out making it fairly clear. It would be great if somehow it remembered function arguments too, and then put out for this case Name "var" already defined as function parameter on line 7 which would make this very clear.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Python の再現コードから始め、mypy 1.10.0 で実行して現在の戻り値エラーを確認します。通常の再定義に対する既存の [no-redef] 診断を追跡し、関数パラメーターの再定義がどこで処理されているかを特定します。サンプルがパラメーター名とその宣言行を明確な診断とともに報告すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100