python / python/mypy

Incorrect mapping of actual to formal arguments.

オープン
#19,692 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug topic-calls
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

def takes_at_least3(a1: str, a2: str, a3: str, *args: str) -> None: ...

def test(
    x0: tuple[str, ...],
    x1: tuple[str, *tuple[str, ...]],
    x2: tuple[str, str, *tuple[str, ...]],
    x3: tuple[str, str, str, *tuple[str, ...]],
) -> None:
    takes_at_least3(*x0)  # no error
    takes_at_least3(*x1)  # Missing positional arguments "x2", "x3"
    takes_at_least3(*x2)  # no error
    takes_at_least3(*x3)  # no error

https://mypy-play.net/?mypy=latest&python=3.12&gist=34662974552c517610691a6b5a792ba2

There are only 2 logically sensible results here:

  1. All of x0-x3 should be accepted
  2. Only x3 should be accepted, since it is the only type that is guaranteed to provide at least 3 items

The choice depends on whether we consider tuple[str, ...] as equal to

  1. The union type tuple[()] | tuple[str] | tuple[str, str] | ...
  2. The gradual AnyOf[tuple[()], tuple[str], tuple[str, str], ... ] (https://github.com/python/typing/issues/566)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた mypy-play の再現例から始め、takes_at_least3 の呼び出しが x0 から x3 に対してどのようにチェックされるかに焦点を当ててください。Issue で提案されている tuple[str, ...] の 2 つの解釈を確認し、どの引数マッピング動作を仕様として定めるべきかを判断してください。選択した動作が一貫して実装され、その例の回帰ケースでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。