Mypy complains about the `all_equal` recipe from the itertools docs
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 5.1k
- Fork
- 2.1k
- Merge medio
- 1g 19h
- PR unite (30g)
- 82
Descrizione
The following function is given as a recipe in the itertools docs, indicating that it's an idiomatic usage of groupby:
from itertools import groupby
def all_equal(iterable):
g = groupby(iterable)
return next(g, True) and not next(g, False)
I think the correct way of adding type annotations to this function would be as follows, since it will work on arbitrary iterables:
from collections.abc import Iterable
from itertools import groupby
def all_equal(iterable: Iterable[object]) -> bool:
g = groupby(iterable)
return next(g, True) and not next(g, False)
Unfortunately, however, mypy complains about this function:
error: Argument 1 to "next" has incompatible type "groupby[object, object]"; expected "SupportsNext[bool]" [arg-type]
(Mypy gives a similar error if I use Iterable[Any] instead of Iterable[object] for the argument annotation.)
Perhaps we should consider copy-and-pasting all the itertools recipes into our test_cases directory. They're all meant to be idiomatic uses of itertools, so if any of them fail to type check, there's probably a problem somewhere.
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
Inizia riproducendo la ricetta all_equal della documentazione di itertools con l'annotazione Iterable proposta e il comportamento attuale di mypy. Esamina la directory test_cases esistente e valuta la possibilità di aggiungervi le ricette di itertools, usando il controllo dei tipi riuscito delle ricette come criterio di completamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- testing, tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100