Demonstrates rewriting the Python AST so that async functions can be transparently called and written.
See the examples for a working demo.
no_asyncio
provides a metaclass that will automatically rewrite methods
that call any function matching a magic string pattern to async functions.
This code:
class MyTest(metaclass=no_asyncio.NoAsync):
magic = 'head'
def __init__(self):
self.session = uvhttp.http.Session(10, loop=asyncio.get_event_loop())
def test_hi(self):
response = self.session.head(b'http://127.0.0.1/')
print(response.status_code)
Becomes rewritten to the following at runtime:
class MyTest(metaclass=no_asyncio.NoAsync):
magic = 'head'
def __init__(self):
self.session = uvhttp.http.Session(10, loop=asyncio.get_event_loop())
async def test_hi(self):
response = await self.session.head(b'http://127.0.0.1/')
print(response.status_code)