Typo in kwarg to overloaded function results in message about type mismatch
オープン
まだ誰も着手していません。
bug
topic-overloads
topic-usability
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
Passing an incorrectly named kwarg to an overloaded function results in a misleading error message about types:
from typing import overload
@overload
def foo(bar: int) -> int:
...
@overload
def foo(bar: None) -> None:
...
def foo(bar: int | None) -> int | None:
...
foo(baz=42) # typo: 'baz' should be 'bar'
error: No overload variant of "foo" matches argument type "int" [call-overload]
note: Possible overload variants:
note: def foo(bar: int) -> int
note: def foo(bar: None) -> None
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.10&gist=0c0b7a4699e67b65d38eb182fb75c444
Expected Behavior
A message such as error: Unexpected keyword argument "baz" for "foo" [call-arg] (which is what you get when the function is not overloaded).
Actual Behavior
error: No overload variant of "foo" matches argument type "int" [call-overload]
Your Environment
- Mypy version used: 1.0.0
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている mypy-play の再現コードから始め、キーワード引数に対する overload 呼び出しのチェックを追跡します。スペルを誤った baz 引数のリグレッションテストを追加し、その後、診断が overload の型不一致ではなく予期しないキーワード引数を報告することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 58/100