Require argument names to match in Protocol
オープン
まだ誰も着手していません。
feature
needs discussion
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
Feature
Currently mypy does not check that argument names in functions that implement protocols match the argument names in the protocol. This fails when arguments are passed as keywords.
For example, this passes mypy:
from typing import Protocol
class MyProtocol(Protocol):
def foo(self, a: int) -> None: ...
class MyObject:
def foo(self, b: int) -> None:
pass
def call_foo(obj: MyProtocol) -> None:
obj.foo(a=1)
call_foo(MyObject())
but fails at runtime:
Traceback (most recent call last):
File "/Users/sidharthkapur/protocol_test.py", line 13, in <module>
call_foo(MyObject())
File "/Users/sidharthkapur/protocol_test.py", line 11, in call_foo
obj.foo(a=1)
TypeError: MyObject.foo() got an unexpected keyword argument 'a'
Pitch
If we checked this in mypy, we could prevent runtime errors like the one above.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue にある Protocol と MyObject の再現コードから始め、それを mypy にかけて現在の動作を確認します。Protocol の実装互換性チェックを追跡し、引数名が一致しない場合とキーワード呼び出しのカバレッジを追加します。完了条件は、mypy が互換性のない実装を拒否しつつ、有効な Protocol 実装を引き続き受け入れることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100