mypy does not recognize conversion between fixed length list and tuple
Offen
Dieses Issue hat noch niemand übernommen.
false-positive
feature
needs discussion
priority-2-low
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- Ø Merge
- 1 T. 18 Std.
- Gemergte PRs (30 T.)
- 54
Beschreibung
- 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
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
Führe zunächst das gemeldete Beispiel in test.py mit mypy aus und bestätige die Diagnose zur Inkompatibilität zwischen Tuple[int, ...] und Tuple[int, int]. Verfolge, wie der Type Checker die Umwandlung von einer Liste fester Länge durch tuple() behandelt, und überprüfe, dass das Beispiel akzeptiert wird, ohne andere, davon unabhängige Typprüfungen abzuschwächen.
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