From: Daniele Varrazzo Date: Tue, 26 Oct 2021 12:14:59 +0000 (+0100) Subject: Fix type hint for `Connection.notifies()` X-Git-Tag: 3.0.2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=400a334c8ea4540f562fd04ff17a6df67a98226d;p=thirdparty%2Fpsycopg.git Fix type hint for `Connection.notifies()` Close #128. --- 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))