From 400a334c8ea4540f562fd04ff17a6df67a98226d Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 26 Oct 2021 13:14:59 +0100 Subject: [PATCH] Fix type hint for `Connection.notifies()` Close #128. --- docs/news.rst | 1 + psycopg/psycopg/connection.py | 6 +++--- psycopg/psycopg/connection_async.py | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index 2dd53875b..921fd4bc0 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -14,6 +14,7 @@ psycopg 3.0.2 ^^^^^^^^^^^^^ - Fix type hint for `sql.SQL.join()` (:ticket:`#127`). +- Fix type hint for `Connection.notifies()` (:ticket:`#128`). psycopg 3.0.1 diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index aeca92668..8815c970c 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -8,8 +8,8 @@ import logging import warnings import threading from types import TracebackType -from typing import Any, Callable, cast, Dict, Generic, Iterator, List -from typing import NamedTuple, Optional, Type, TypeVar, Union +from typing import Any, Callable, cast, Dict, Generator, Generic, Iterator +from typing import List, NamedTuple, Optional, Type, TypeVar, Union from typing import overload, TYPE_CHECKING from weakref import ref, ReferenceType from functools import partial @@ -743,7 +743,7 @@ class Connection(BaseConnection[Row]): with Transaction(self, savepoint_name, force_rollback) as tx: yield tx - def notifies(self) -> Iterator[Notify]: + def notifies(self) -> Generator[Notify, None, None]: """ Yield `Notify` objects as soon as they are received from the database. """ diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index 69b8bee0b..5e0b8e9a5 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -8,8 +8,8 @@ import sys import asyncio import logging from types import TracebackType -from typing import Any, AsyncIterator, Dict, Optional, Type, Union -from typing import cast, overload, TYPE_CHECKING +from typing import Any, AsyncGenerator, AsyncIterator, Dict, Optional +from typing import Type, Union, cast, overload, TYPE_CHECKING from . import errors as e from . import waiting @@ -275,7 +275,7 @@ class AsyncConnection(BaseConnection[Row]): async with tx: yield tx - async def notifies(self) -> AsyncIterator[Notify]: + async def notifies(self) -> AsyncGenerator[Notify, None]: while 1: async with self.lock: ns = await self.wait(notifies(self.pgconn)) -- 2.47.2