nvbn / py-backwards

Python to python compiler that allows you to use Python 3.6 features in older versions.
306 stars 17 forks source link

wishlist: asyncio desugaring #2

Open chrysn opened 7 years ago

chrysn commented 7 years ago

python 3.5 and 3.6 have made asynchronous code much more straightforward to write, and while there were some changes in the execution model, much code can run with just desugaring, for example

Some backward compatibility tricks could also be useful in here (eg. adding __iter__ = __await__ to all classes that define an __await__).

Would that (or which of this would) be feasible for py-backwards to include?

graingert commented 7 years ago

@chrysn here's something I was messing around with to get async generators working https://gist.github.com/graingert/f19fcca51eec3e27111dc738925f358c/

graingert commented 7 years ago

Also would be worth getting the https://pypi.python.org/pypi/trollius package back up and running

nvbn commented 7 years ago

@graingert seems like it can be done in two steps:

graingert commented 7 years ago

@nvbn yep that was the idea behind my code. Happy to license it freely if someone want to make sure it's safe.

chrysn commented 7 years ago

actually I think it's three steps; @graingert's gist demos the target-3.5 step of async yielding. for target-3.4, the await would need to become yield from. (and on targetting < 3.4 i can't comment).

graingert commented 7 years ago

@chrysn well no, you'd convert the runtime helper module once

graingert commented 7 years ago

@nvbn most of the complexity in trollius was supporting python 2.7 and 3.x at the same time with eval. It was also manually converted from 3.4

A fork of trollius with all of that replaced with py-backwards transpiling would be needed.

nvbn commented 7 years ago

@chrysn yep, three steps would be better, and there's already "transformer" for yield from.

@graingert we can use https://pypi.python.org/pypi/asyncio for 3.3 and trollius for older version.

Seems like it will be a very complicated transformation =)

chrysn commented 7 years ago

Seems like it will be a very complicated transformation =)

Can we keep the steps independent of each other? (Ie. should we split up the issue by target?)

The 3.5 to 3.4 steps should be by far the easiest (it could be done in a regexp, not that we'd do it that way), and the difficulty of pre-3.4 targets shouldn't keep that back.