Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return None and some other fix #1237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions asyncpg/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def __init__(self, *connect_args,
loop,
connection_class,
record_class,
**connect_kwargs):
**connect_kwargs) -> None:

if len(connect_args) > 1:
warnings.warn(
Expand Down Expand Up @@ -442,7 +442,7 @@ async def _async__init__(self):
self._initializing = False
self._initialized = True

async def _initialize(self):
async def _initialize(self) -> None:
self._queue = asyncio.LifoQueue(maxsize=self._maxsize)
for _ in range(self._maxsize):
ch = PoolConnectionHolder(
Expand Down Expand Up @@ -475,42 +475,42 @@ async def _initialize(self):

await asyncio.gather(*connect_tasks)

def is_closing(self):
def is_closing(self) -> bool:
"""Return ``True`` if the pool is closing or is closed.

.. versionadded:: 0.28.0
"""
return self._closed or self._closing

def get_size(self):
def get_size(self) -> int:
"""Return the current number of connections in this pool.

.. versionadded:: 0.25.0
"""
return sum(h.is_connected() for h in self._holders)

def get_min_size(self):
def get_min_size(self) -> int:
"""Return the minimum number of connections in this pool.

.. versionadded:: 0.25.0
"""
return self._minsize

def get_max_size(self):
def get_max_size(self) -> int:
"""Return the maximum allowed number of connections in this pool.

.. versionadded:: 0.25.0
"""
return self._maxsize

def get_idle_size(self):
def get_idle_size(self) -> int:
"""Return the current number of idle connections in this pool.

.. versionadded:: 0.25.0
"""
return sum(h.is_connected() and h.is_idle() for h in self._holders)

def set_connect_args(self, dsn=None, **connect_kwargs):
def set_connect_args(self, dsn=None, **connect_kwargs) -> None:
r"""Set the new connection arguments for this pool.

The new connection arguments will be used for all subsequent
Expand Down Expand Up @@ -574,7 +574,7 @@ async def _get_new_connection(self):

return con

async def execute(self, query: str, *args, timeout: float=None) -> str:
async def execute(self, query: str, *args, timeout: Optional[float] = None) -> str:
"""Execute an SQL command (or commands).

Pool performs this operation using one of its connections. Other than
Expand All @@ -586,7 +586,7 @@ async def execute(self, query: str, *args, timeout: float=None) -> str:
async with self.acquire() as con:
return await con.execute(query, *args, timeout=timeout)

async def executemany(self, command: str, args, *, timeout: float=None):
async def executemany(self, command: str, args, *, timeout: Optional[float] = None):
"""Execute an SQL *command* for each sequence of arguments in *args*.

Pool performs this operation using one of its connections. Other than
Expand Down Expand Up @@ -925,7 +925,7 @@ async def release(self, connection, *, timeout=None):
# pool properly.
return await asyncio.shield(ch.release(timeout))

async def close(self):
async def close(self) -> None:
"""Attempt to gracefully close all connections in the pool.

Wait until all pool connections are released, close them and
Expand Down Expand Up @@ -970,13 +970,13 @@ async def close(self):
self._closed = True
self._closing = False

def _warn_on_long_close(self):
def _warn_on_long_close(self) -> None:
logger.warning('Pool.close() is taking over 60 seconds to complete. '
'Check if you have any unreleased connections left. '
'Use asyncio.wait_for() to set a timeout for '
'Pool.close().')

def terminate(self):
def terminate(self) -> None:
"""Terminate all connections in the pool."""
if self._closed:
return
Expand All @@ -985,7 +985,7 @@ def terminate(self):
ch.terminate()
self._closed = True

async def expire_connections(self):
async def expire_connections(self) -> None:
"""Expire all currently open connections.

Cause all currently open connections to get replaced on the
Expand All @@ -995,7 +995,7 @@ async def expire_connections(self):
"""
self._generation += 1

def _check_init(self):
def _check_init(self) -> None:
if not self._initialized:
if self._initializing:
raise exceptions.InterfaceError(
Expand All @@ -1006,13 +1006,13 @@ def _check_init(self):
if self._closed:
raise exceptions.InterfaceError('pool is closed')

def _drop_statement_cache(self):
def _drop_statement_cache(self) -> None:
# Drop statement cache for all connections in the pool.
for ch in self._holders:
if ch._con is not None:
ch._con._drop_local_statement_cache()

def _drop_type_cache(self):
def _drop_type_cache(self) -> None:
# Drop type codec cache for all connections in the pool.
for ch in self._holders:
if ch._con is not None:
Expand All @@ -1021,11 +1021,11 @@ def _drop_type_cache(self):
def __await__(self):
return self._async__init__().__await__()

async def __aenter__(self):
async def __aenter__(self) -> Pool:
await self._async__init__()
return self

async def __aexit__(self, *exc):
async def __aexit__(self, *exc) -> None:
await self.close()


Expand Down