]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Alias Task to asyncio.Future for python version < 3.8
authorDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 13 Apr 2021 08:06:32 +0000 (10:06 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 16 Apr 2021 11:28:53 +0000 (12:28 +0100)
This resolves the following mypy error on Python 3.7:

  psycopg3/psycopg3/pool/async_pool.py:72: error: Argument 1 to "append" of "list" has incompatible type "Future[None]"; expected "Task[None]" [arg-type]

psycopg3/psycopg3/pool/async_pool.py
psycopg3/psycopg3/utils/compat.py

index 0c4d38217a2bce854e86b51152d446ab890dcdc0..7c950c1c21a878bafa0bd28dbb6045735d10ef00 100644 (file)
@@ -18,7 +18,7 @@ from collections import deque
 from .. import errors as e
 from ..pq import TransactionStatus
 from ..connection import AsyncConnection
-from ..utils.compat import asynccontextmanager, create_task
+from ..utils.compat import Task, asynccontextmanager, create_task
 
 from .base import ConnectionAttempt, BasePool
 from .sched import AsyncScheduler
@@ -57,7 +57,7 @@ class AsyncConnectionPool(BasePool[AsyncConnection]):
 
         self._sched = AsyncScheduler()
         self._tasks: "asyncio.Queue[MaintenanceTask]" = asyncio.Queue()
-        self._workers: "List[asyncio.Task[None]]" = []
+        self._workers: List[Task[None]] = []
 
         super().__init__(conninfo, **kwargs)
 
index 57ae8d2f555f2e607d48fe43053a0afebfac2896..0bbe62e32fcd9f2278ed5740e5cd8342aa094206 100644 (file)
@@ -24,6 +24,7 @@ else:
 
 if sys.version_info >= (3, 8):
     create_task = asyncio.create_task
+    Task = asyncio.Task
 
 elif sys.version_info >= (3, 7):
 
@@ -32,6 +33,7 @@ elif sys.version_info >= (3, 7):
     ) -> "asyncio.Future[T]":
         return asyncio.create_task(coro)
 
+    Task = asyncio.Future
 
 else:
 
@@ -40,5 +42,6 @@ else:
     ) -> "asyncio.Future[T]":
         return asyncio.ensure_future(coro)
 
+    Task = asyncio.Future
 
 __all__ = ["asynccontextmanager", "get_running_loop", "create_task"]