Skip to content

Commit 17f2079

Browse files
committed
Fix Py37 deprecation warning regarding asyncio.Task.current_task()
1 parent 78ea13a commit 17f2079

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

asyncpg/compat.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
66

77

8+
import asyncio
89
import functools
910
import os
1011
import pathlib
@@ -13,6 +14,7 @@
1314

1415

1516
PY_36 = sys.version_info >= (3, 6)
17+
PY_37 = sys.version_info >= (3, 7)
1618
SYSTEM = platform.uname().system
1719

1820

@@ -69,3 +71,11 @@ def get_pg_home_directory() -> pathlib.Path:
6971
else:
7072
def get_pg_home_directory() -> pathlib.Path:
7173
return pathlib.Path.home()
74+
75+
76+
if PY_37:
77+
def current_asyncio_task(loop):
78+
return asyncio.current_task(loop)
79+
else:
80+
def current_asyncio_task(loop):
81+
return asyncio.Task.current_task(loop)

asyncpg/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ async def _cancel(self, waiter):
11591159
waiter.set_exception(ex)
11601160
finally:
11611161
self._cancellations.discard(
1162-
asyncio.Task.current_task(self._loop))
1162+
compat.current_asyncio_task(self._loop))
11631163
if not waiter.done():
11641164
waiter.set_result(None)
11651165
if w is not None:

0 commit comments

Comments
 (0)