python / python/mypy

False-positive with multiple *args splats in a function call

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

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

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

説明

Bug Report

mypy falsely(?) reports a type error when the *args syntax is used more than once in a function call.

To Reproduce

mypy --no-incremental --config /dev/null -c '
def foobar(a: int, b: str, c: int) -> None:
    ...


foo = (1,)
bar = ("b", 3)

foobar(*foo, *bar)
'

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

<string>:9: error: Argument 2 to "foobar" has incompatible type "*Tuple[str, int]"; expected "str"
<string>:9: error: Argument 2 to "foobar" has incompatible type "*Tuple[str, int]"; expected "int"

This error goes away if I:

  • make foo an int instead of Tuple[int], and remove the splat when foobar() is called.
  • make bar two ints and make foobar() take three int arguments.
  • make foo a Tuple[str, int] and make foobar() take str, int, str, int arguments.
  • make bar just a Tuple[str] and make foobar() take int, str arguments.

Your Environment

This occurs with the standard version of mypy in Debian Testing:

$ /usr/bin/mypy --version
mypy 0.812

...as well as with the latest git revision:

$ ~/.local/pipx/venvs/mypy/bin/mypy --version
mypy 0.820+dev.8642b351cff94c471333256f9cd6867807384f01

In both cases, I'm using the Debian-provided Python 3.9.2,
on up-to-date Debian Testing.

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

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

はじめの一歩

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

調査の方向性

まず、提供されている mypy コマンドを実行し、複数の tuple splat を含む呼び出しについて 2 つの診断を確認します。次に、呼び出し引数のチェックと tuple-splat の処理を追跡し、この再現例のカバレッジを追加します。完了条件は、一覧にあるバリエーションをリグレッションさせずに、コマンドが問題を報告しないことです。

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

評価

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

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

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