Report protocol problems in no_variant_matches_arguments if possible
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Feature
Report protocol problems in no_variant_matches_arguments if possible.
Pitch
Given following example:
from typing import Protocol, overload
class Foo(Protocol):
def some_method(self, value: int = 0) -> None: ...
class Bar:
def some_method(self, value: int) -> None:
pass
@overload
def accept_foo(value: Foo, v: int) -> None:
pass
@overload
def accept_foo(value: Foo, v: float) -> None:
pass
def accept_foo(value: Foo, v: int | float) -> None:
pass
accept_foo(Bar(), 1)
The Bar has conflict with the Protocol Foo, but currently Mypy won't report the protocol problems. This is the current error report:
protocol_example.py:27: error: No overload variant of "accept_foo" matches argument types "Bar", "int" [call-overload]
protocol_example.py:27: note: Possible overload variants:
protocol_example.py:27: note: def accept_foo(value: Foo, v: int) -> None
protocol_example.py:27: note: def accept_foo(value: Foo, v: float) -> None
Found 1 error in 1 file (checked 1 source file)
If we can report the protocol problems in this case, it may save developers time to figure out what' wrong.
I did a proof-of-concept implementation here: https://github.com/python/mypy/commit/a2040d3680320afbac6e13b3b04593a7965242bc. This is the updated error report:
protocol_example.py:27: error: No overload variant of "accept_foo" matches argument types "Bar", "int" [call-overload]
protocol_example.py:27: note: Following member(s) of "Bar" have conflicts:
protocol_example.py:27: note: Expected:
protocol_example.py:27: note: def some_method(self, value: int = ...) -> None
protocol_example.py:27: note: Got:
protocol_example.py:27: note: def some_method(self, value: int) -> None
protocol_example.py:27: note: Expected:
protocol_example.py:27: note: def some_method(self, value: int = ...) -> None
protocol_example.py:27: note: Got:
protocol_example.py:27: note: def some_method(self, value: int) -> None
protocol_example.py:27: note: Possible overload variants:
protocol_example.py:27: note: def accept_foo(value: Foo, v: int) -> None
protocol_example.py:27: note: def accept_foo(value: Foo, v: float) -> None
Found 1 error in 1 file (checked 1 source file)
If this is OK, I'd happy to refine the implementation and submit a PR.
Thanks.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
no_variant_matches_arguments のエントリポイントから始め、issue にリンクされた proof-of-concept commit を確認してください。提供された Protocol と overload の例を再現し、診断が競合するメンバーを重複した、または誤解を招く出力なしに正確に報告することを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers, devtools
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100