"Overloaded function implementation does not accept all possible arguments"
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- Ø Merge
- 1 T. 18 Std.
- Gemergte PRs (30 T.)
- 54
Beschreibung
False positive; mypy doesn't believe that Foo[T] is a subtype of T.
from typing import Union, Generic, TypeVar, overload
T = TypeVar("T")
class Foo(Generic[T]):
pass
@overload
def expect(pattern: Foo[T]) -> None: ...
@overload
def expect(pattern: T) -> None: ...
def expect(pattern: Union[Foo[T], T]) -> None: return None
$ mypy xxx.py
xxx.py:14: error: Overloaded function implementation does not accept all possible arguments of signature 1
Note that the second overload referencing the type variable used in the first overload is necessary; if pattern: int is used instead of pattern: T in the second overload, mypy type-checks the file correctly.
Environment
- Mypy version used: 0.910
- Python version used: 3.10 and 3.7
- Operating system and version: Fedora 34
Related issues
- #11004: mypy thinks
**kwargs: Union[None, int, str]overload isn't accepted by**kwargs: Any - #9420: mypy thinks
Type[T1]isn't accepted byUnion[Type[T1], Type[T2]] - #9023: same bug with two different type variables
I think that #10390 fixes this issue, but I'm not sure.
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
Reproduziere die Diagnose in xxx.py mit mypy unter Verwendung der gezeigten Overloads und lies anschließend die verwandten Issues #10390, #11004, #9420 und #9023, um die bestehende Behandlung zu verstehen. Erledigt bedeutet, dass die gültige Overload-Implementierung ohne den gemeldeten Fehler akzeptiert wird und die Regression durch die Tests des Projekts abgedeckt ist.
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
- 42/100