]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Make the async pool unavailable on Python 3.6
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 8 Mar 2021 01:05:09 +0000 (02:05 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 12 Mar 2021 04:07:25 +0000 (05:07 +0100)
Because of https://bugs.python.org/issue42600 or thereabout.

psycopg3/psycopg3/pool/async_pool.py
tests/pool/test_pool.py
tests/pool/test_pool_async.py

index a8400aa1b63ae29f96d5f38e108436de9cabb34a..ca41c21ff06c6e9cce8fa7897db56339a696fce6 100644 (file)
@@ -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()
index 77993c74d2a9ccc159f21fbecff2f06512fac2fb..fec574c3ca67b69c8a7b55dce1204d7960688b37 100644 (file)
@@ -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
index 246bccffa02b4b3b58baacf30b27ec771039e120..810643f8dd427b93d8bde9777d9fd1716a02939d 100644 (file)
@@ -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):