seatgeek / tornado-async-transformer

libcst transformer that replaces tornado's legacy @gen.coroutine syntax with python3.5+ native async/await

Home Page:https://tornado-async-transformer.now.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tornado Async Transformer

A libcst transformer for updating tornado @gen.coroutine syntax to python3.5+ native async/await.

Check out the demo.

Usage

You can either:

  • Add tornado_async_transformer.TornadoAsyncTransformer to your existing libcst codemod.
  • Or run python -m tornado_async_transformer.tool my_project/ from the commandline.

Example

 """
 A simple coroutine.
 """
 from tornado import gen


-@gen.coroutine
-def call_api():
-    response = yield fetch()
+async def call_api():
+    response = await fetch()
     if response.status != 200:
         raise BadStatusError()
-    raise gen.Return(response.data)
+    return response.data

About

libcst transformer that replaces tornado's legacy @gen.coroutine syntax with python3.5+ native async/await

https://tornado-async-transformer.now.sh

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 93.4%Language:JavaScript 3.5%Language:HTML 2.4%Language:CSS 0.7%