From bec31e3d805fe40b4ac65d46b259491c4b7c60ff Mon Sep 17 00:00:00 2001 From: pradhvan Date: Wed, 11 Sep 2019 17:32:15 +0530 Subject: [PATCH] docs/index.rst: Updated tutorial to native coroutines This updates the old styled @asyncio.coroutine -> async def coroutine and updates yield from -> await. Closes https://github.com/aio-libs/aiomysql/issues/436 --- docs/index.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 303fdf3c..684d08c1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -19,7 +19,7 @@ of :term:`PyMySQL` . **aiomysql** tries to be like awesome aiopg_ library and pr same api, look and feel. Internally **aiomysql** is copy of PyMySQL, underlying io calls switched -to async, basically ``yield from`` and ``asyncio.coroutine`` added in +to async, basically ``await`` and ``async def coroutine`` added in proper places. :term:`sqlalchemy` support ported from aiopg_. @@ -36,7 +36,7 @@ Basics ------ **aiomysql** based on :term:`PyMySQL` , and provides same api, you just need -to use ``yield from conn.f()`` instead of just call ``conn.f()`` for +to use ``await conn.f()`` instead of just call ``conn.f()`` for every method. Properties are unchanged, so ``conn.prop`` is correct as well as @@ -51,18 +51,18 @@ See example: loop = asyncio.get_event_loop() - @asyncio.coroutine - def test_example(): - conn = yield from aiomysql.connect(host='127.0.0.1', port=3306, + + async def test_example(): + conn = await aiomysql.connect(host='127.0.0.1', port=3306, user='root', password='', db='mysql', loop=loop) - cur = yield from conn.cursor() - yield from cur.execute("SELECT Host,User FROM user") + cur = await conn.cursor() + await cur.execute("SELECT Host,User FROM user") print(cur.description) - r = yield from cur.fetchall() + r = await cur.fetchall() print(r) - yield from cur.close() + await cur.close() conn.close() loop.run_until_complete(test_example())