From: Daniele Varrazzo Date: Fri, 15 May 2020 08:07:43 +0000 (+1200) Subject: Generators types moved to proto module X-Git-Tag: 3.0.dev0~521 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5eb37b77793a4f2e4edb5ff59640d31219b8a81d;p=thirdparty%2Fpsycopg.git Generators types moved to proto module --- diff --git a/psycopg3/connection.py b/psycopg3/connection.py index 437b7015c..b4b14c093 100644 --- a/psycopg3/connection.py +++ b/psycopg3/connection.py @@ -22,7 +22,7 @@ from .waiting import wait, wait_async logger = logging.getLogger(__name__) if TYPE_CHECKING: - from .generators import PQGen, RV + from .proto import PQGen, RV class BaseConnection: diff --git a/psycopg3/generators.py b/psycopg3/generators.py index 14f5ba911..6b89bfc33 100644 --- a/psycopg3/generators.py +++ b/psycopg3/generators.py @@ -16,15 +16,12 @@ when the file descriptor is ready. # Copyright (C) 2020 The Psycopg Team import logging -from typing import Generator, List, Tuple, TypeVar +from typing import List from .waiting import Wait, Ready from . import pq from . import errors as e - -# Generic type of a libpq protocol generator. -RV = TypeVar("RV") -PQGen = Generator[Tuple[int, Wait], Ready, RV] +from .proto import PQGen logger = logging.getLogger(__name__) diff --git a/psycopg3/proto.py b/psycopg3/proto.py index 7e92a2765..edf6f3283 100644 --- a/psycopg3/proto.py +++ b/psycopg3/proto.py @@ -5,8 +5,9 @@ Protocol objects representing different implementations of the same classes. # Copyright (C) 2020 The Psycopg Team import codecs -from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional -from typing import Sequence, Tuple, Type, Union, TYPE_CHECKING +from typing import Any, Callable, Dict, Generator, Iterable, List, Mapping +from typing import Optional, Sequence, Tuple, Type, TypeVar, Union +from typing import TYPE_CHECKING from typing_extensions import Protocol from . import pq @@ -15,17 +16,26 @@ if TYPE_CHECKING: from .connection import BaseConnection # noqa from .cursor import BaseCursor # noqa from .adapt import Dumper, Loader # noqa + from .waiting import Wait, Ready # noqa # Part of the module interface (just importing it makes mypy unhappy) Format = pq.Format - EncodeFunc = Callable[[str], Tuple[bytes, int]] DecodeFunc = Callable[[bytes], Tuple[str, int]] Query = Union[str, bytes] Params = Union[Sequence[Any], Mapping[str, Any]] + +# Waiting protocol types + +RV = TypeVar("RV") +PQGen = Generator[Tuple[int, "Wait"], "Ready", RV] + + +# Adaptation types + AdaptContext = Union[None, "BaseConnection", "BaseCursor", "Transformer"] MaybeOid = Union[Optional[bytes], Tuple[Optional[bytes], int]] diff --git a/psycopg3/waiting.py b/psycopg3/waiting.py index 967eb0b5b..7ce2f54e1 100644 --- a/psycopg3/waiting.py +++ b/psycopg3/waiting.py @@ -10,14 +10,12 @@ These functions are designed to consume the generators returned by the from enum import IntEnum -from typing import Optional, TYPE_CHECKING +from typing import Optional from asyncio import get_event_loop, Event from selectors import DefaultSelector, EVENT_READ, EVENT_WRITE from . import errors as e - -if TYPE_CHECKING: - from .generators import PQGen, RV +from .proto import PQGen, RV class Wait(IntEnum):