[Python-Dev] PEP 492: async/await in Python; version 4

Steven D'Aprano steve at pearwood.info
Sun May 3 17:24:40 CEST 2015

On Fri, May 01, 2015 at 09:24:47PM +0100, Arnaud Delobelle wrote:

> I'm not convinced that allowing an object to be both a normal and an
> async iterator is a good thing.  It could be a recipe for confusion.

In what way?

I'm thinking that the only confusion would be if you wrote "async for" 
instead of "for", or vice versa, and instead of getting an exception you 
got the (a)syncronous behaviour you didn't want.

But I have no intuition for how likely it is that you could write an 
asyncronous for loop, leave out the async, and still have the code do 
something meaningful.

Other than that, I think it would be fine to have an object be both a 
syncronous and asyncronous iterator. You specify the behaviour you want 
by how you use it. We can already do that, e.g. unittest's assertRaises 
is both a test assertion and a context manager.

Objects can have multiple roles, and it's not usually abused, or 
confusing. I'm not sure that async iterables will be any different.


More information about the Python-Dev mailing list