python / python/mypy

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

Offen
#10,481 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den bereitgestellten mypy-Befehl auszuführen und die beiden Diagnosen für den Aufruf mit mehreren Tuple-Splats zu bestätigen. Verfolge anschließend die Prüfung der Aufrufargumente und die Behandlung von Tuple-Splats und füge eine Testabdeckung für diesen Reproducer hinzu; abgeschlossen ist die Aufgabe, wenn der Befehl ohne Probleme meldet, dass keine der aufgeführten Variationen regressiert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.