Irritable implements broken iterators called irritables
- Free software: BSD license
- Documentation: https://irritable.readthedocs.io.
Iterators are defined in the docs; the definition includes what constitutes a broken implementation:
4.5. Iterator Types
[...]
Once an iterator’s
__next__()
method raises StopIteration, it must continue to do so on subsequent calls. Implementations that do not obey this property are deemed broken.
Irritables are like iterables, but deliberately broken. The following types of brokenness are supported:
- after
next()
first raisesStopIteration
, subsequent calls will raiseStopIrritation
instead; - if the irritator is instantiated with
resume=True
, callingnext()
may raiseStopIteration
when items remain still remain in the container; subsequent calls tonext()
will return the remaining items as usual until none remain; - if the irritator is instantiated with
repeat=True
, after the iterator has been exhausted and raisesStopIteration
, the iterator is reset and can be iterated over again ad infinitum; in this casenext()
will never raiseStopIrritation
;
The idea for irritators came during Trey Hunner's talk "Loop better: a deeper look at iteration in Python" at DjangoCon AU 2017.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.