Copy with slicing of a list[subclass] should be ok for list[superclass]
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
-
Are you reporting a bug, or opening a feature request?
As I expected this to work, I assume it 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.
from typing import List
class Upi(object):
pass
class Subi(Upi):
pass
subs = [Subi(), Subi()]
ok1:List[Upi] = [s for s in subs]
ok2:List[Upi] = list(subs)
notOk:List[Upi] = subs[:] # this should also be ok IMHO
-
What is the actual behavior/output?
notOk list is not ok for mypy. -
What is the behavior/output you expect?
Should be ok. Actually saw this in a function return value so should be ok there also when function is returning list of superclass things. -
What are the versions of mypy and Python you are using?
mypy 0.720, Python 3.7.3 -
What are the mypy flags you are using? (For example --strict-optional)
None
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
Das Issue nennt keine Implementierungsdateien oder Tests. Beginne damit, die bereitgestellte Reproduktion mit mypy auszuführen, und verfolge dann, wie das Slicing von Listen im Vergleich zu einer Comprehension und list(subs) typisiert wird. Als erledigt gilt die Aufgabe, wenn die Zuweisung von subs[:] zu List[Upi] ohne Flags akzeptiert wird und eine Abdeckung für den gemeldeten Fall vorhanden 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
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100