Variadic `*args` where `args: Union[Tuple[...], Tuple[...], ...]` are _never_ checked [False Negative]
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
When args is a Union of two or more fixed-length Tuples, and some_func() is callable, the following call is always accepted without error (regardless of what's in the tuples!):
some_func(*args)
To Reproduce
from __future__ import annotations
from typing import (
Tuple,
Union,
)
class ClassA: pass
class ClassB: pass
class ClassC: pass
def some_func(value: ClassA, /) -> None:
pass
u_bc: Union[Tuple[ClassB], Tuple[ClassC]]
some_func(*u_bc) # expected: [type-arg]; got: no error
Expected Behavior
Mypy should notice that one or more of the Tuples that make up the Union are not appropriate for the callable, and complain about the argument types accordingly.
Put another way, mypy should examine each possibility posed by the Union in turn, and complain if any of them isn't suitable for the variadic call.
Actual Behavior
Mypy always accepts variadic arguments of this form, without any regard to the contents of the Tuples that make up the Union.
Your Environment
- Mypy version used: 1.9.0 (also checked 1.5, 1.0; this doesn't appear to be a recent regression)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.8, 3.12
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
El reproductor de mypy-play.net es el punto de partida; ejecuta el ejemplo mostrado de Python 3.12 e inspecciona cómo gestiona mypy los *args variádicos de una Union de Tuples de longitud fija. Se considera terminado cuando la llamada informa de un error de tipo de argumento para alternativas de tupla incompatibles, tal como se describe en Expected Behavior.
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
- 45/100