mypy does not recognize conversion between fixed length list and tuple
Aperta
Nessuno ha ancora preso questa issue.
false-positive
feature
needs discussion
priority-2-low
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
- Are you reporting a bug, or opening a feature request?
I believe this is a bug
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
Minimal example to reproduce:
from typing import List, Tuple
def get_point_as_list() -> List[int]:
return [1, 2]
def point_to_tuple(pt: List[int]) -> Tuple[int, int]:
assert len(pt) == 2
return tuple(pt)
if __name__ == "__main__":
l = get_point_as_list()
p = point_to_tuple(l)
print(repr(p))
- What is the actual behavior/output?
mypy test.py
test.py:10: error: Incompatible return value type (got "Tuple[int, ...]", expected "Tuple[int, int]")
- What is the behavior/output you expect?
mypy should evaluate this as correct code
- What are the versions of mypy and Python you are using?
Do you see the same issue after installing mypy from Git master?
$ mypy --version
mypy 0.720
$ python --version
Python 3.7.3
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
Inizia eseguendo con mypy l'esempio segnalato in test.py e conferma la diagnostica di incompatibilità tra Tuple[int, ...] e Tuple[int, int]. Traccia il modo in cui il type checker gestisce la conversione tramite tuple() di una lista di lunghezza fissa e verifica che l'esempio venga accettato senza indebolire controlli di tipo non correlati.
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