Yury Selivanov added the comment:

Please see the attached patch.

Couple of notes:

1. It adds a new type: 'coroutine' (PyCoro_Type).  The implementation is still 
heavily based on generators, there are no changes there.

2. Unfortunately, a new opcode needs to be added - GET_YIELD_FROM_ITER. The 
idea is that YIELD_FROM from generators decorated with @coroutine must accept
'async def' coroutines.  But 'for' loops (iter(), etc) must throw an error on 
them.  On the bright side, because of this new opcode, the ceval code became 
much easier to follow.

3. This change removes the need to use __instancecheck__ for 'async def' 
coroutines.  BUT, it's still there for generators decorated with @coroutine.  
Stefan suggests to wrap generators in a thin wrapper with __await__ method, but 
I don't like this idea -- it will inevitably make existing asyncio code slower 
in 3.5; I'm -0.5 on this idea.

4. While this patch addresses initial request from Ben only partially 
(generator-based coroutines still require __instancecheck__), I believe that 
it's still a good idea to separate 'async def' coroutines & generators in 3.5.  
I'm fully confident that we shouldn't have any issues with that.

----------
keywords: +patch
Added file: http://bugs.python.org/file39664/corotype.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24400>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to