From: Denis Laxalde Date: Tue, 9 Apr 2024 07:19:27 +0000 (+0200) Subject: fix: fix type signature of to_thread() compat X-Git-Tag: 3.2.0~54^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F763%2Fhead;p=thirdparty%2Fpsycopg.git fix: fix type signature of to_thread() compat --- diff --git a/psycopg/psycopg/_compat.py b/psycopg/psycopg/_compat.py index 8d5d48aa9..7ffd76b8b 100644 --- a/psycopg/psycopg/_compat.py +++ b/psycopg/psycopg/_compat.py @@ -16,16 +16,18 @@ if sys.version_info >= (3, 9): from collections.abc import Callable else: import asyncio - from typing import Callable, Counter, Deque + from typing import Callable, Counter, Deque, TypeVar from functools import lru_cache from backports.zoneinfo import ZoneInfo cache = lru_cache(maxsize=None) - async def to_thread(func: Callable[..., Any], /, *args: Any, **kwargs: Any) -> None: + R = TypeVar("R") + + async def to_thread(func: Callable[..., R], /, *args: Any, **kwargs: Any) -> R: loop = asyncio.get_running_loop() func_call = partial(func, *args, **kwargs) - await loop.run_in_executor(None, func_call) + return await loop.run_in_executor(None, func_call) if sys.version_info >= (3, 10):