Wrong "Too many arguments" errors with tuple unpacking
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
Bug Report
I'm getting wrong or misleading "Too many arguments" errors when using tuple unpacking in function calls.
To Reproduce
from typing import Tuple
def x(x: int, y: int) -> None:
print(x, y)
def foo1(t: tuple) -> None:
x(*t[:1], 1)
def foo2(t: tuple) -> None:
x(*t[:2])
def foo3(t: Tuple[int]) -> None:
x(*t[:1], 1)
mypy reports:
$ mypy sandbox.py
sandbox.py:7: error: Too many arguments for "x"
Found 1 error in 1 file (checked 1 source file)
(Line 7 is the call to x in foo1)
Expected Behavior
The call to x in foo1 will never have too many arguments -- it has either 1 (if t is empty) or 2 (if t is not empty). I would have expected an error regarding the possibility of t being empty (i.e. "Potentially not enough arguments").
Also I think that foo1 and foo2 share the same issues regarding their calls of x, so I would have expected to get the same errors for both of them.
Actual Behavior
The call to x in foo1 is reported, but the call to x in foo2 isn't. Interestingly, fixing the tuple length (as in foo3) seems to fix the issue.
Your Environment
- Mypy version used: 0.790
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.8.5
- Operating system and version: Ubuntu 18.04.5
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 gli esempi in sandbox.py con mypy nell’ambiente Python 3.8.5 indicato e confronta le diagnosi per foo1, foo2 e foo3. Traccia il controllo degli argomenti con l’unpacking di tuple a partire dalla chiamata che fallisce, quindi aggiungi una copertura di regressione per la gestione prevista di ogni esempio e verifica che le diagnosi siano coerenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100