Variadic `*args` where `args: Union[Tuple[...], Tuple[...], ...]` are _never_ checked [False Negative]
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Der mypy-play.net-Reproducer ist der Ausgangspunkt; führe das gezeigte Python-3.12-Beispiel aus und untersuche, wie mypy variadische *args aus einer Union von Tupeln fester Länge behandelt. Als erledigt gilt die Aufgabe, wenn der Aufruf für inkompatible Tupelalternativen einen Argumenttypfehler meldet, wie unter Expected Behavior beschrieben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100