Skip to content

Commit 18f3e1b

Browse files
committed
Fix for metaclass errors in Python 3.6
1 parent 8332c03 commit 18f3e1b

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

asyncpg/connection.py

+15-2
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`.
@@ -2375,6 +2383,11 @@ async def _do_execute(
23752383
return result, stmt
23762384

23772385

2386+
if sys.version_info < (3, 7):
2387+
# see: https://bugs.python.org/issue41451
2388+
del Connection.__slots__
2389+
2390+
23782391
@typing.overload
23792392
async def connect(dsn: typing.Optional[str] = ..., *,
23802393
host: typing.Optional[connect_utils.HostType] = ...,

asyncpg/pool.py

+12-2
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
@@ -24,7 +25,7 @@
2425
_Record = typing.TypeVar('_Record', bound=protocol.Record)
2526

2627

27-
class PoolConnectionProxyMeta(type):
28+
class _PoolConnectionProxyMeta(type):
2829

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

6768

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

0 commit comments

Comments
 (0)