valhallasw added a subscriber: valhallasw. valhallasw added a comment.
It has to do with the hairy business of iterators versus generators in python:
## current code
class IteratorExample(object): def __iter__(self): yield 1 i = IteratorExample() print list(i) print list(i) # this is confusing
## 'typical' use of __iter__
class IteratorExample(object): def __init__(self): self.returnvalues = [1] def __iter__(self): return self def next(self): try: return self.returnvalues.pop() except: raise StopIteration()
i = IteratorExample() print list(i) print list(i) # this now makes sense
## how to go from (1) to (2) with minimal changes?
class IteratorExample(object): def __init__(self): self.gen = self._gen() def _gen(self): yield 1 def __iter__(self): return self def next(self): return self.gen.next()
i = IteratorExample() print list(i) print list(i) # this now makes sense, but the boilerplate code is... meh.
TASK DETAIL https://phabricator.wikimedia.org/T85204
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: valhallasw Cc: Aklapper, Daviskr, valhallasw, jayvdb, pywikipedia-bugs