Passing a list as an argument with * leads to confusing error

Offen
#3,224 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

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

Rechercherichtung

The issue names no source file or test. Start by reproducing the minimal Python example and trace mypy's handling of starred list arguments and its diagnostic location. Done means the diagnostic is corrected to identify the second argument, or the valid call is accepted if that behavior is implemented.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

topic-calls topic-error-reporting topic-usability

(Originally reported at https://github.com/python/typeshed/issues/814, which gives an example from real code.)

def foo(a: int, b: str = '') -> None: ...

foo(1)  # OK
foo(*[1])  # E: Argument 1 to "foo" has incompatible type *List[int]; expected "str"

Ideally this shouldn't be an error at all (this works fine at runtime), but I imagine it's hard for mypy to accept this code since it doesn't know how long the list is. However, we could at least fix the error message, which talks about "argument 1" needing to be a str when really it's argument 2 that is the problem.

Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
Ø Merge
1 T. 18 Std.
Gemergte PRs (30 T.)
54

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/mypy

Alle Issues in python/mypy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

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