Fixed-size, multi-type sequence
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
Descrizione
This came up in python/typeshed#2287, but I have encountered the same problem myself. As far as I know, currently the only way to annotate a multi-type, fixed length sequence is using Tuple. But for input types this is often too strict:
def foo(x: Tuple[int, str]) -> None:
a, b = x
def bar(x: Tuple[int, str]) -> None:
a = x[0]
b = x[1]
The implementations accept any iterable (first case) or sequence (second case) that yield two values:
class Iter:
def __iter__(self):
yield 1
yield ""
foo((1, ""))
foo([1, ""])
foo(Iter())
bar((1, ""))
bar([1, ""])
It would be useful to have a way to annotate this. Of course type checkers would still need to reject generic cases like this:
def foo(x: TupleLike[str, str]): ...
x: List[str] = ...
foo(x)
But it could allow some things that are not possible at the moment, and opens the possibility for future improvements.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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 leggendo python/typeshed#2287 e gli esempi di questa issue, quindi esamina come typing rappresenta attualmente tuple, iterabili e sequenze. L’issue non indica file di implementazione o test; per considerarla completata sarebbe necessario concordare un design delle annotazioni che supporti gli input descritti, preservando al contempo utili restrizioni sul controllo dei tipi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100