mypy incorrectly reports incompatible return types for overloaded methods
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
@overload
def foo(cls: type[dict], mapping: SupportsKeysAndGetItem[K, V], /) -> dict[K, V]: ...
@overload
def foo(cls: type[dict], mapping: SupportsKeysAndGetItem[str, V], /, **kwargs: V) -> dict[str, V]: ...
Return types are compatible.
class FrozendictBase(Generic[K, V]):
@overload
def __new__(
cls,
mapping: SupportsKeysAndGetItem[K, V],
/,
) -> 'FrozendictBase[K, V]': ...
@overload
def __new__(
cls,
mapping: SupportsKeysAndGetItem[str, V],
/,
**kwargs: V,
) -> 'FrozendictBase[str, V]': ...
Return types are also compatible, but mypy reports an error.
To Reproduce
- Download file.txt and save as
sandbox.py. - Run
mypy sandbox.py.
Expected Behavior
sandbox.py:8: error: Invariant type variable "V" used in protocol where covariant one is expected
This is due to #5775.
Actual Behavior
sandbox.py:8: error: Invariant type variable "V" used in protocol where covariant one is expected
sandbox.py:39: error: Overloaded function signatures 3 and 4 overlap with incompatible return types
sandbox.py:54: error: Overloaded function signatures 5 and 6 overlap with incompatible return types
Your Environment
- Mypy version used: mypy 0.950
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: Python 3.10.4
- Operating system and version: Windows 10
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
Scarica il file collegato e salvalo come sandbox.py, quindi esegui mypy sandbox.py per riprodurre le diagnostiche degli overload. Analizza le segnalazioni di tipo restituito incompatibile per le firme sovraccaricate 3/4 e 5/6; il lavoro è completato quando tali segnalazioni non compaiono più, mentre rimane l’errore previsto della variabile di tipo invariante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers, devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100