Copy with slicing of a list[subclass] should be ok for list[superclass]
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
-
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
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
La issue non indica file di implementazione né test. Inizia eseguendo la riproduzione fornita con mypy, quindi traccia il modo in cui viene tipizzato lo slicing delle liste rispetto a una comprehension e a list(subs). Il lavoro è completato quando l’assegnazione di subs[:] a List[Upi] viene accettata senza flags, con una copertura per il caso segnalato.
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
- Specificata chiaramente
- Idoneità per principianti
- 45/100