Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f091228

Browse files
Fix for metaclass errors in Python 3.6
1 parent 75466f4 commit f091228

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

‎asyncpg/connection.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,22 @@ def __call__(
103103
...
104104

105105

106-
class ConnectionMeta(type):
106+
class _ConnectionMeta(type):
107107

108108
def __instancecheck__(cls, instance: typing.Any) -> bool:
109109
mro = type(instance).__mro__
110110
return Connection in mro or _ConnectionProxy in mro
111111

112112

113-
class Connection(typing.Generic[_Record], metaclass=ConnectionMeta):
113+
if sys.version_info >= (3, 7):
114+
ConnectionMeta = _ConnectionMeta
115+
else:
116+
# see: https://github.com/python/typing/issues/449
117+
class ConnectionMeta(_ConnectionMeta, typing.GenericMeta):
118+
...
119+
120+
121+
class Connection(typing.Generic[_Record], metaclass=ConnectionMeta): # type: ignore[misc] # noqa: E501
114122
"""A representation of a database session.
115123
116124
Connections are created by calling :func:`~asyncpg.connection.connect`.
@@ -2424,6 +2432,11 @@ async def _do_execute(
24242432
return result, stmt
24252433

24262434

2435+
if sys.version_info < (3, 7):
2436+
# see: https://bugs.python.org/issue41451
2437+
del Connection.__slots__
2438+
2439+
24272440
@typing.overload
24282441
async def connect(dsn: typing.Optional[str] = ..., *,
24292442
host: typing.Optional[connect_utils.HostType] = ...,

‎asyncpg/pool.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import functools
1010
import inspect
1111
import logging
12+
import sys
1213
import time
1314
import typing
1415
import warnings
@@ -25,7 +26,7 @@
2526
_Record = typing.TypeVar('_Record', bound=protocol.Record)
2627

2728

28-
class PoolConnectionProxyMeta(type):
29+
class _PoolConnectionProxyMeta(type):
2930

3031
def __new__(mcls, name, bases, dct, *, wrap=False):
3132
if wrap:
@@ -66,7 +67,16 @@ def call_con_method(self, *args, **kwargs):
6667
return call_con_method
6768

6869

69-
class PoolConnectionProxy(connection._ConnectionProxy,
70+
if sys.version_info >= (3, 7):
71+
PoolConnectionProxyMeta = _PoolConnectionProxyMeta
72+
else:
73+
# see: https://github.com/python/typing/issues/449
74+
class PoolConnectionProxyMeta(_PoolConnectionProxyMeta,
75+
typing.GenericMeta):
76+
...
77+
78+
79+
class PoolConnectionProxy(connection._ConnectionProxy[_Record],
7080
metaclass=PoolConnectionProxyMeta,
7181
wrap=True):
7282

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /