micropython / micropython/micropython-lib
itertools.tee wrongly programmed
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 2.9k
- Forks
- 1.1k
- Ø Merge
- 7 T. 6 Std.
- Gemergte PRs (30 T.)
- 3
Beschreibung
The crux of the tee() function of itertools is that in duplicates/multiplies the generator so that you have independent generator copies: If one is depleated (StopIteration Exception) the others still are able to generate the sequence.
MPs itertools tee definition:
def tee(iterable, n=2):
return [iter(iterable)] * n
does not achieve this.
My very first example from the book "Clean Code in Python" by Mariano Anaya using tee thus lead to an error.
Circuitpythons itertools practically has the same definition. -> same problem.
tee in CPython has to store the objects that some, but not all of the generator copies have produced. It is coded in C.
I see no other way to replicate this behaviour than to grow a list of those values. A deque with the option to retrieve intermediate objects would be optimal, which we do not have?!
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
Lies zunächst die im Issue gezeigte Definition von itertools tee() und vergleiche ihr Verhalten mit der tee-Implementierung von CPython. Reproduziere den Fall, in dem ein Iterator vor den anderen erschöpft ist; die Aufgabe ist abgeschlossen, wenn die zurückgegebenen Iteratoren unabhängig bleiben und weiterhin die Sequenz erzeugen können.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100