Better message for overloaded functions with required kwargs
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Feature
The following:
from typing import overload, Union
def fun(a: Union[int, str], *, b: bool) -> None:
pass
fun(1, True)
says helpfully:
main.py:6: error: Too many positional arguments for "fun" [misc]
Found 1 error in 1 file (checked 1 source file)
In the following case however:
from typing import overload, Union
@overload
def fun(a: int, *, b: bool) -> None: ...
@overload
def fun(a: str, *, b: bool) -> None: ...
def fun(a: Union[int, str], *, b: bool) -> None:
pass
fun(1, True)
we get:
main.py:12: error: No overload variant of "fun" matches argument types "int", "bool" [call-overload]
main.py:12: note: Possible overload variants:
main.py:12: note: def fun(a: int, *, b: bool) -> None
main.py:12: note: def fun(a: str, *, b: bool) -> None
Found 1 error in 1 file (checked 1 source file)
I think the error should also point out that the number of positional arguments is incorrect.
Pitch
I found myself confused by this a couple of times and have wasted good few hours trying to understand what's wrong with the call which is clearly correct, and just glancing straight past the * - something that's easy to do with a longer / more complicated function signature. I think it would save a meaningful amount of time for users and it feels like a simple change.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci entrambi gli esempi Python nei casi collegati di mypy-playground e confronta le relative diagnosi. Il lavoro è completato quando l’errore della funzione sovraccaricata spiega anche che il numero di argomenti posizionali non è valido, mantenendo i dettagli dei sovraccarichi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100