Wrong "Too many arguments" errors with tuple unpacking
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce los ejemplos de sandbox.py con mypy en el entorno de Python 3.8.5 indicado y compara los diagnósticos para foo1, foo2 y foo3. Rastrea la comprobación de argumentos con desempaquetado de tuplas desde la llamada que falla; después, añade cobertura de regresión para el comportamiento esperado de cada ejemplo y verifica que los diagnósticos sean coherentes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100