]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Generators types moved to proto module
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 15 May 2020 08:07:43 +0000 (20:07 +1200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 17 May 2020 09:29:34 +0000 (21:29 +1200)
psycopg3/connection.py
psycopg3/generators.py
psycopg3/proto.py
psycopg3/waiting.py

index 437b7015cecbddc797323e4ef12ea241f6843a2e..b4b14c093546ef11a06d3b70abdec99a173f3e01 100644 (file)
@@ -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:
index 14f5ba9118bda68f4ba61ca1d0483a943f530727..6b89bfc332730501a9d98cb0eaa1c140568dbc1d 100644 (file)
@@ -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__)
 
index 7e92a276542a207a9dbbb22e01220b9606b067bf..edf6f32836f3471cc67533ff88a8dc5235744ef0 100644 (file)
@@ -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]]
index 967eb0b5b6e8449f5706ad3cd96e76a428fec2c5..7ce2f54e152e425ee395bc001948367f1b8acca7 100644 (file)
@@ -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):