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

Mark pool-wrapped connection coroutine methods as coroutines #1134

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions asyncpg/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ async def wait_closed(stream: asyncio.StreamWriter) -> None:
pass


if sys.version_info < (3, 12):
def markcoroutinefunction(c): # type: ignore
pass
else:
from inspect import markcoroutinefunction # noqa: F401


if sys.version_info < (3, 12):
from ._asyncio_compat import wait_for as wait_for # noqa: F401
else:
Expand Down
8 changes: 6 additions & 2 deletions asyncpg/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def __new__(mcls, name, bases, dct, *, wrap=False):
if not inspect.isfunction(meth):
continue

wrapper = mcls._wrap_connection_method(attrname)
iscoroutine = inspect.iscoroutinefunction(meth)
wrapper = mcls._wrap_connection_method(attrname, iscoroutine)
wrapper = functools.update_wrapper(wrapper, meth)
dct[attrname] = wrapper

Expand All @@ -43,7 +44,7 @@ def __new__(mcls, name, bases, dct, *, wrap=False):
return super().__new__(mcls, name, bases, dct)

@staticmethod
def _wrap_connection_method(meth_name):
def _wrap_connection_method(meth_name, iscoroutine):
def call_con_method(self, *args, **kwargs):
# This method will be owned by PoolConnectionProxy class.
if self._con is None:
Expand All @@ -55,6 +56,9 @@ def call_con_method(self, *args, **kwargs):
meth = getattr(self._con.__class__, meth_name)
return meth(self._con, *args, **kwargs)

if iscoroutine:
compat.markcoroutinefunction(call_con_method)

return call_con_method


Expand Down