# 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__)
# 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
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]]
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):