From 432151942ccf6db5abb3eddab04ba0253795dc3a Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Tue, 9 Apr 2024 09:19:27 +0200 Subject: [PATCH] fix: fix type signature of to_thread() compat --- psycopg/psycopg/_compat.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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): -- 2.39.5