From: Daniele Varrazzo Date: Mon, 8 Mar 2021 01:05:09 +0000 (+0100) Subject: Make the async pool unavailable on Python 3.6 X-Git-Tag: 3.0.dev0~87^2~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=997d3d81d22b138729cbe51de231a063a48c1480;p=thirdparty%2Fpsycopg.git Make the async pool unavailable on Python 3.6 Because of https://bugs.python.org/issue42600 or thereabout. --- diff --git a/psycopg3/psycopg3/pool/async_pool.py b/psycopg3/psycopg3/pool/async_pool.py index a8400aa1b..ca41c21ff 100644 --- a/psycopg3/psycopg3/pool/async_pool.py +++ b/psycopg3/psycopg3/pool/async_pool.py @@ -4,6 +4,7 @@ psycopg3 synchronous connection pool # Copyright (C) 2021 The Psycopg Team +import sys import asyncio import logging from abc import ABC, abstractmethod @@ -14,6 +15,7 @@ from typing import List, Optional, Type from weakref import ref from collections import deque +from .. import errors as e from ..pq import TransactionStatus from ..connection import AsyncConnection from ..utils.compat import asynccontextmanager, create_task @@ -34,6 +36,12 @@ class AsyncConnectionPool(BasePool[AsyncConnection]): ] = None, **kwargs: Any, ): + # https://bugs.python.org/issue42600 + if sys.version_info < (3, 7): + raise e.NotSupportedError( + "async pool not supported before Python 3.7" + ) + self._configure = configure self._lock = asyncio.Lock() diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 77993c74d..fec574c3c 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -1,3 +1,4 @@ +import sys import logging import weakref from time import sleep, time @@ -680,6 +681,16 @@ def test_check(dsn, caplog): assert pid not in pids2 +@pytest.mark.skipif( + sys.version_info >= (3, 7), reason="async pool supported from Python 3.7" +) +def test_async_pool_not_supported(dsn): + # note: this test is here because the all the ones in test_pool_async are + # skipped on Py 3.6 + with pytest.raises(psycopg3.NotSupportedError): + pool.AsyncConnectionPool(dsn) + + def delay_connection(monkeypatch, sec): """ Return a _connect_gen function delayed by the amount of seconds diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 246bccffa..810643f8d 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -1,3 +1,4 @@ +import sys import asyncio import logging import weakref @@ -11,7 +12,13 @@ from psycopg3 import pool from psycopg3.pq import TransactionStatus from psycopg3.utils.compat import create_task -pytestmark = pytest.mark.asyncio +pytestmark = [ + pytest.mark.asyncio, + pytest.mark.skipif( + sys.version_info < (3, 7), + reason="async pool not supported before Python 3.7", + ), +] async def test_defaults(dsn):