Idea: add Char type to represent Text with size = 1
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
L’issue non indica file, test o punti di ingresso; inizia esaminando la semantica proposta di Char e Text nell’issue. Il lavoro è completato quando esiste un design concordato che copre il comportamento iterabile, l’indicizzazione e lo slicing, la compatibilità e le regole di concatenazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Due to the lack of character type in Python, a function that accept List[Text] will need to be extra careful when generalize the accepted argument type. Iterable[Text] and Sequence[Text] clearly doesn't work:
In [1]: import collections.abc
In [2]: isinstance("foo", collections.abc.Sequence)
Out[2]: True
In [3]: isinstance("foo", collections.abc.Iterable)
Out[3]: True
The closest thing you can do is to do something like Union[List[Text], Set[Text], Tuple[Text]] but it will not work with things like KeysView.
How about having a typing.Char to represent Text with length=1, and dedicate Text to a type with at least 2 characters?
Some examples to illustrate the usage:
def foo(xs: Iterable[Text]):
return '|'.join(xs)
# list(Text) should return List[Char]
foo("abcd") # error
foo(list("abcd")) # correct, List[Char] is a special case of List[Text]
def bar(xs: Iterable[Char]):
return '|'.join(xs)
bar("abcd") # correct, Text is a Iterable[Char]
bar(list("abcd")) # correct, List[Char] is a Iterable[Char]
bar(["ab", "cd"]) # error, List[Text] is not a Iterable[Char]
a: Char = 'a'
a[1] # error, Char cannot be indexed beyond index 0
a[0] # should be an error from type checking's PoV, Char should never be indexed
a[:] # should be an error from type checking's PoV, Char should never be copied as a slice
b: Text = 'b'
a + b # should be an error from type checking's PoV, Char and Text should be considered incompatible types
typing.cast(Text, a) + b # correct
c = a + a # correct, concatenate Char gets Text (but I'm not sure if this is reasonable though, what if we do (a + a) + a ?)
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
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.
Altre issue di python/typing
-
topic: typing spec
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
topic: typing spec
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
topic: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
topic: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
topic: conformance tests topic: typing spec
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
Tutte le issue di python/typing
Issue simili
-
triage/confirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
apache/cloudstack#14222 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100