Skip to content

Commit

Permalink
Use asyncio.run() instead of run_until_complete()
Browse files Browse the repository at this point in the history
Mostly in the documentation.
  • Loading branch information
eltoder committed Mar 21, 2024
1 parent 1aab209 commit 955c167
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ Basic Usage
)
await conn.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
asyncio.run(run())
License
Expand Down
16 changes: 8 additions & 8 deletions asyncpg/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ async def copy_from_table(self, table_name, *, output,
... output='file.csv', format='csv')
... print(result)
...
>>> asyncio.get_event_loop().run_until_complete(run())
>>> asyncio.run(run())
'COPY 100'
.. _`COPY statement documentation`:
Expand Down Expand Up @@ -869,7 +869,7 @@ async def copy_from_query(self, query, *args, output,
... output='file.csv', format='csv')
... print(result)
...
>>> asyncio.get_event_loop().run_until_complete(run())
>>> asyncio.run(run())
'COPY 10'
.. _`COPY statement documentation`:
Expand Down Expand Up @@ -945,7 +945,7 @@ async def copy_to_table(self, table_name, *, source,
... 'mytable', source='datafile.tbl')
... print(result)
...
>>> asyncio.get_event_loop().run_until_complete(run())
>>> asyncio.run(run())
'COPY 140000'
.. _`COPY statement documentation`:
Expand Down Expand Up @@ -1027,7 +1027,7 @@ async def copy_records_to_table(self, table_name, *, records,
... (2, 'ham', 'spam')])
... print(result)
...
>>> asyncio.get_event_loop().run_until_complete(run())
>>> asyncio.run(run())
'COPY 2'
Asynchronous record iterables are also supported:
Expand All @@ -1045,7 +1045,7 @@ async def copy_records_to_table(self, table_name, *, records,
... 'mytable', records=record_gen(100))
... print(result)
...
>>> asyncio.get_event_loop().run_until_complete(run())
>>> asyncio.run(run())
'COPY 100'
.. versionadded:: 0.11.0
Expand Down Expand Up @@ -1305,7 +1305,7 @@ async def set_type_codec(self, typename, *,
... print(result)
... print(datetime.datetime(2002, 1, 1) + result)
...
>>> asyncio.get_event_loop().run_until_complete(run())
>>> asyncio.run(run())
relativedelta(years=+2, months=+3, days=+1)
2004-04-02 00:00:00
Expand Down Expand Up @@ -1772,7 +1772,7 @@ async def reload_schema_state(self):
... await con.execute('LOCK TABLE tbl')
... await change_type(con)
...
>>> asyncio.get_event_loop().run_until_complete(run())
>>> asyncio.run(run())
.. versionadded:: 0.14.0
"""
Expand Down Expand Up @@ -2258,7 +2258,7 @@ async def connect(dsn=None, *,
... types = await con.fetch('SELECT * FROM pg_type')
... print(types)
...
>>> asyncio.get_event_loop().run_until_complete(run())
>>> asyncio.run(run())
[<Record typname='bool' typnamespace=11 ...
.. versionadded:: 0.10.0
Expand Down
2 changes: 1 addition & 1 deletion asyncpg/pgproto
Submodule pgproto updated 1 files
+2 −0 codecs/__init__.pxd
3 changes: 1 addition & 2 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ a need to run the same query again.
.. code-block:: pycon
>>> import asyncpg, asyncio
>>> loop = asyncio.get_event_loop()
>>> async def run():
... conn = await asyncpg.connect()
... stmt = await conn.prepare('''SELECT 2 ^ $1''')
... print(await stmt.fetchval(10))
... print(await stmt.fetchval(20))
...
>>> loop.run_until_complete(run())
>>> asyncio.run(run())
1024.0
1048576.0
Expand Down
7 changes: 3 additions & 4 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ which provides methods to run queries and manage transactions.
# Close the connection.
await conn.close()
asyncio.get_event_loop().run_until_complete(main())
asyncio.run(main())
.. note::
Expand Down Expand Up @@ -344,7 +343,7 @@ shows how to instruct asyncpg to use floats instead.
finally:
await conn.close()
asyncio.get_event_loop().run_until_complete(main())
asyncio.run(main())
Example: decoding hstore values
Expand All @@ -369,7 +368,7 @@ be registered on a connection using :meth:`Connection.set_builtin_type_codec()
result = await conn.fetchval("SELECT 'a=>1,b=>2,c=>NULL'::hstore")
assert result == {'a': '1', 'b': '2', 'c': None}
asyncio.get_event_loop().run_until_complete(run())
asyncio.run(run())
.. _hstore: https://www.postgresql.org/docs/current/static/hstore.html

Expand Down
5 changes: 1 addition & 4 deletions tools/generate_type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ def main():
help='PostgreSQL server user')

args = parser.parse_args()

loop = asyncio.get_event_loop()

loop.run_until_complete(runner(args))
asyncio.run(runner(args))


if __name__ == '__main__':
Expand Down

0 comments on commit 955c167

Please sign in to comment.