Skip to content

Commit

Permalink
Use loop.create_future directly (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner authored Dec 12, 2020
1 parent b5880d2 commit b5d3490
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
10 changes: 5 additions & 5 deletions aiopg/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from psycopg2.extensions import POLL_ERROR, POLL_OK, POLL_READ, POLL_WRITE

from .cursor import Cursor
from .utils import _ContextManager, create_future, get_running_loop
from .utils import _ContextManager, get_running_loop

__all__ = ('connect',)

Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(
self._enable_hstore = enable_hstore
self._enable_uuid = enable_uuid
self._loop = get_running_loop(kwargs.pop('loop', None) is not None)
self._waiter = create_future(self._loop)
self._waiter = self._loop.create_future()

kwargs['async_'] = kwargs.pop('async', True)
self._conn = psycopg2.connect(dsn, **kwargs)
Expand Down Expand Up @@ -181,15 +181,15 @@ def _create_waiter(self, func_name):
raise RuntimeError('%s() called while another coroutine is '
'already waiting for incoming '
'data' % func_name)
self._waiter = create_future(self._loop)
self._waiter = self._loop.create_future()
return self._waiter

async def _poll(self, waiter, timeout):
assert waiter is self._waiter, (waiter, self._waiter)
self._ready(self._weakref)

async def cancel():
self._waiter = create_future(self._loop)
self._waiter = self._loop.create_future()
self._cancelling = True
self._cancellation_waiter = self._waiter
self._conn.cancel()
Expand Down Expand Up @@ -307,7 +307,7 @@ def free_cursor(self):

def close(self):
self._close()
ret = create_future(self._loop)
ret = self._loop.create_future()
ret.set_result(None)
return ret

Expand Down
3 changes: 1 addition & 2 deletions aiopg/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
_PoolConnectionContextManager,
_PoolContextManager,
_PoolCursorContextManager,
create_future,
ensure_future,
get_running_loop,
)
Expand Down Expand Up @@ -230,7 +229,7 @@ async def _wakeup(self):
def release(self, conn):
"""Release free connection back to the connection pool.
"""
fut = create_future(self._loop)
fut = self._loop.create_future()
fut.set_result(None)
if conn in self._terminated:
assert conn.closed, conn
Expand Down
7 changes: 0 additions & 7 deletions aiopg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ def get_running_loop(is_warn: bool = False) -> asyncio.AbstractEventLoop:
return loop


def create_future(loop):
try:
return loop.create_future()
except AttributeError:
return asyncio.Future(loop=loop)


class _ContextManager(Coroutine):
__slots__ = ('_coro', '_obj')

Expand Down

0 comments on commit b5d3490

Please sign in to comment.