Skip to content

Commit 0d12215

Browse files
committed
Use asyncio.run() instead of run_until_complete()
Mostly in the documentation.
1 parent 1aab209 commit 0d12215

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

README.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ Basic Usage
8888
)
8989
await conn.close()
9090
91-
loop = asyncio.get_event_loop()
92-
loop.run_until_complete(run())
91+
asyncio.run(run())
9392
9493
9594
License

asyncpg/connection.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ async def copy_from_table(self, table_name, *, output,
800800
... output='file.csv', format='csv')
801801
... print(result)
802802
...
803-
>>> asyncio.get_event_loop().run_until_complete(run())
803+
>>> asyncio.run(run())
804804
'COPY 100'
805805
806806
.. _`COPY statement documentation`:
@@ -869,7 +869,7 @@ async def copy_from_query(self, query, *args, output,
869869
... output='file.csv', format='csv')
870870
... print(result)
871871
...
872-
>>> asyncio.get_event_loop().run_until_complete(run())
872+
>>> asyncio.run(run())
873873
'COPY 10'
874874
875875
.. _`COPY statement documentation`:
@@ -945,7 +945,7 @@ async def copy_to_table(self, table_name, *, source,
945945
... 'mytable', source='datafile.tbl')
946946
... print(result)
947947
...
948-
>>> asyncio.get_event_loop().run_until_complete(run())
948+
>>> asyncio.run(run())
949949
'COPY 140000'
950950
951951
.. _`COPY statement documentation`:
@@ -1027,7 +1027,7 @@ async def copy_records_to_table(self, table_name, *, records,
10271027
... (2, 'ham', 'spam')])
10281028
... print(result)
10291029
...
1030-
>>> asyncio.get_event_loop().run_until_complete(run())
1030+
>>> asyncio.run(run())
10311031
'COPY 2'
10321032
10331033
Asynchronous record iterables are also supported:
@@ -1045,7 +1045,7 @@ async def copy_records_to_table(self, table_name, *, records,
10451045
... 'mytable', records=record_gen(100))
10461046
... print(result)
10471047
...
1048-
>>> asyncio.get_event_loop().run_until_complete(run())
1048+
>>> asyncio.run(run())
10491049
'COPY 100'
10501050
10511051
.. versionadded:: 0.11.0
@@ -1305,7 +1305,7 @@ async def set_type_codec(self, typename, *,
13051305
... print(result)
13061306
... print(datetime.datetime(2002, 1, 1) + result)
13071307
...
1308-
>>> asyncio.get_event_loop().run_until_complete(run())
1308+
>>> asyncio.run(run())
13091309
relativedelta(years=+2, months=+3, days=+1)
13101310
2004-04-02 00:00:00
13111311
@@ -1772,7 +1772,7 @@ async def reload_schema_state(self):
17721772
... await con.execute('LOCK TABLE tbl')
17731773
... await change_type(con)
17741774
...
1775-
>>> asyncio.get_event_loop().run_until_complete(run())
1775+
>>> asyncio.run(run())
17761776
17771777
.. versionadded:: 0.14.0
17781778
"""
@@ -2258,7 +2258,7 @@ async def connect(dsn=None, *,
22582258
... types = await con.fetch('SELECT * FROM pg_type')
22592259
... print(types)
22602260
...
2261-
>>> asyncio.get_event_loop().run_until_complete(run())
2261+
>>> asyncio.run(run())
22622262
[<Record typname='bool' typnamespace=11 ...
22632263
22642264
.. versionadded:: 0.10.0

docs/api/index.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ a need to run the same query again.
3636
.. code-block:: pycon
3737
3838
>>> import asyncpg, asyncio
39-
>>> loop = asyncio.get_event_loop()
4039
>>> async def run():
4140
... conn = await asyncpg.connect()
4241
... stmt = await conn.prepare('''SELECT 2 ^ $1''')
4342
... print(await stmt.fetchval(10))
4443
... print(await stmt.fetchval(20))
4544
...
46-
>>> loop.run_until_complete(run())
45+
>>> asyncio.run(run())
4746
1024.0
4847
1048576.0
4948

docs/usage.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ which provides methods to run queries and manage transactions.
4444
# Close the connection.
4545
await conn.close()
4646
47-
asyncio.get_event_loop().run_until_complete(main())
48-
47+
asyncio.run(main())
4948
5049
5150
.. note::
@@ -344,7 +343,7 @@ shows how to instruct asyncpg to use floats instead.
344343
finally:
345344
await conn.close()
346345
347-
asyncio.get_event_loop().run_until_complete(main())
346+
asyncio.run(main())
348347
349348
350349
Example: decoding hstore values
@@ -369,7 +368,7 @@ be registered on a connection using :meth:`Connection.set_builtin_type_codec()
369368
result = await conn.fetchval("SELECT 'a=>1,b=>2,c=>NULL'::hstore")
370369
assert result == {'a': '1', 'b': '2', 'c': None}
371370
372-
asyncio.get_event_loop().run_until_complete(run())
371+
asyncio.run(run())
373372
374373
.. _hstore: https://www.postgresql.org/docs/current/static/hstore.html
375374

tools/generate_type_map.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ def main():
124124
help='PostgreSQL server user')
125125

126126
args = parser.parse_args()
127-
128-
loop = asyncio.get_event_loop()
129-
130-
loop.run_until_complete(runner(args))
127+
asyncio.run(runner(args))
131128

132129

133130
if __name__ == '__main__':

0 commit comments

Comments
 (0)