Variadic `*args` where `args: Union[Tuple[...], Tuple[...], ...]` are _never_ checked [False Negative]
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
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
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
Il riproduttore mypy-play.net è il punto di partenza; esegui l'esempio mostrato di Python 3.12 e analizza come mypy gestisce gli *args variadici provenienti da una Union di Tuple di lunghezza fissa. Il lavoro è completato quando la chiamata segnala un errore di tipo dell'argomento per alternative di tupla incompatibili, come descritto in Expected Behavior.
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
- 45/100