The source transformation route has not been very popular with Python 2 vs. 3 porting projects.
I wonder if it would be possible (using asyncio internals) to write a From() function that lets you write "yield From(x)" instead of "yield from x" in Tulip? On Thu, Feb 20, 2014 at 8:51 AM, Yury Selivanov <[email protected]>wrote: > > On 2/20/2014, 11:42 AM, Antoine Pitrou wrote: > >> On Thu, 20 Feb 2014 11:30:21 -0500 >> Yury Selivanov <[email protected]> >> wrote: >> >>> Cons: >>> >>> - I don't see any, really. 'From' wrappers will have a small >>> performance cost, but I'm sure it will be negligible. >>> >> From what I understand, you still can't write a library that works with >> both trollius and asyncio. >> >> A possibility for a 2.x- and 3.x-compatible library is to use callback >> style rather than coroutine style. It may even allow you to be >> compatible with Tornado. >> >> > Right, you still can't do it in a straightforward way. > But you can write a tool to convert python3 'yield from' > to something that Trollius can work with (be it plain 'yield' > or 'yield From'). Writing such tool will require: > > - parsing the python code (doable) > > - writing an AST analyzer to pick functions defined with > @coroutine (doable) > > - writing an AST transformer to replace 'yield from' > with 'yield' or 'yield From' (very doable, once you have > two first items) > > - dumping the transformed code back > > [I'm not sure if 3to2 can be reused for this]. > > My proposal is two-fold: > > 1. A tool (set of tools) to convert native asyncio code > in Trollius code; > > 2. Using 'yield From' in Trollius to ease migration to > python3 and asyncio in the future; and to ease debugging of > code ported from asyncio to Trollius. > > Yury > > -- --Guido van Rossum (python.org/~guido)
