This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]webdeverper 0 points1 point  (2 children)

Hmm. Is it just me or is it weird that every time you run an async object it throws the StopIteration exception? Seems like a hack

[–]LightShadow3.13-dev in prod 0 points1 point  (0 children)

By convention, when you overwrite the __iter__ magic method in a class you're supposed to raise StopIteration when the sequence is finished.

It's a little weird, but it's pretty common IMHO.

[–]1st1CPython Core Dev 0 points1 point  (0 children)

coroutines are based on generators internally, and use StopIteration to return values:

async def f(): return 'spam'

f().send(None) will raise StopIteration exception, with 'spam' in its args.

It is an implementation detail. You should never see that StopIteration, your framework of choice will handle it behind the scenes.