From: Daniele Varrazzo Date: Wed, 24 Jun 2020 14:17:20 +0000 (+1200) Subject: Some mypy cleanup X-Git-Tag: 3.0.dev0~474 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08d068bca7e9b85853ca28111ae3f6b501bd67f9;p=thirdparty%2Fpsycopg.git Some mypy cleanup --- diff --git a/psycopg3/_psycopg3.pyi b/psycopg3/_psycopg3.pyi index ca26da420..87cd90596 100644 --- a/psycopg3/_psycopg3.pyi +++ b/psycopg3/_psycopg3.pyi @@ -15,8 +15,6 @@ from .proto import LoadFunc, LoadersMap, LoaderType, MaybeOid, PQGen from .connection import BaseConnection from . import pq -Format = pq.Format - class Transformer: def __init__(self, context: AdaptContext = None): ... @property @@ -28,25 +26,29 @@ class Transformer: @property def loaders(self) -> LoadersMap: ... @property - def pgresult(self) -> Optional["pq.proto.PGresult"]: ... + def pgresult(self) -> Optional[pq.proto.PGresult]: ... @pgresult.setter - def pgresult(self, result: Optional["pq.proto.PGresult"]) -> None: ... - def set_row_types(self, types: Sequence[Tuple[int, Format]]) -> None: ... + def pgresult(self, result: Optional[pq.proto.PGresult]) -> None: ... + def set_row_types( + self, types: Sequence[Tuple[int, pq.Format]] + ) -> None: ... def dump_sequence( - self, objs: Iterable[Any], formats: Iterable[Format] + self, objs: Iterable[Any], formats: Iterable[pq.Format] ) -> Tuple[List[Optional[bytes]], List[int]]: ... - def dump(self, obj: None, format: Format = Format.TEXT) -> MaybeOid: ... - def get_dump_function(self, src: type, format: Format) -> DumpFunc: ... - def lookup_dumper(self, src: type, format: Format) -> DumperType: ... + def dump( + self, obj: None, format: pq.Format = pq.Format.TEXT + ) -> MaybeOid: ... + def get_dump_function(self, src: type, format: pq.Format) -> DumpFunc: ... + def lookup_dumper(self, src: type, format: pq.Format) -> DumperType: ... def load_row(self, row: int) -> Optional[Tuple[Any, ...]]: ... def load_sequence( self, record: Sequence[Optional[bytes]] ) -> Tuple[Any, ...]: ... def load( - self, data: bytes, oid: int, format: Format = Format.TEXT + self, data: bytes, oid: int, format: pq.Format = pq.Format.TEXT ) -> Any: ... - def get_load_function(self, oid: int, format: Format) -> LoadFunc: ... - def lookup_loader(self, oid: int, format: Format) -> LoaderType: ... + def get_load_function(self, oid: int, format: pq.Format) -> LoadFunc: ... + def lookup_loader(self, oid: int, format: pq.Format) -> LoaderType: ... def register_builtin_c_loaders() -> None: ... def connect(conninfo: str) -> PQGen[pq.proto.PGconn]: ... diff --git a/psycopg3/adapt.py b/psycopg3/adapt.py index cd97715b1..d3fc9c78d 100644 --- a/psycopg3/adapt.py +++ b/psycopg3/adapt.py @@ -8,14 +8,12 @@ from typing import Any, Callable, Optional, Tuple, Type, Union from . import pq from . import proto +from .pq import Format as Format from .proto import AdaptContext, DumpersMap, DumperType from .proto import LoadersMap, LoaderType from .cursor import BaseCursor from .connection import BaseConnection -# Part of the module interface (just importing it makes mypy unhappy) -Format = pq.Format - class Dumper: globals: DumpersMap = {} diff --git a/psycopg3/proto.py b/psycopg3/proto.py index edf6f3283..1a4ac3140 100644 --- a/psycopg3/proto.py +++ b/psycopg3/proto.py @@ -11,15 +11,13 @@ from typing import TYPE_CHECKING from typing_extensions import Protocol from . import pq +from .pq import Format 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 + from .connection import BaseConnection + from .cursor import BaseCursor + from .adapt import Dumper, Loader + from .waiting import Wait, Ready EncodeFunc = Callable[[str], Tuple[bytes, int]] DecodeFunc = Callable[[bytes], Tuple[str, int]] @@ -61,11 +59,11 @@ class Transformer(Protocol): ... @property - def pgresult(self) -> Optional["pq.proto.PGresult"]: + def pgresult(self) -> Optional[pq.proto.PGresult]: ... @pgresult.setter - def pgresult(self, result: Optional["pq.proto.PGresult"]) -> None: + def pgresult(self, result: Optional[pq.proto.PGresult]) -> None: ... @property diff --git a/psycopg3/transform.pyx b/psycopg3/transform.pyx index d184867ae..63205cb86 100644 --- a/psycopg3/transform.pyx +++ b/psycopg3/transform.pyx @@ -149,11 +149,11 @@ cdef class Transformer: return self._loaders @property - def pgresult(self) -> Optional["pq.proto.PGresult"]: + def pgresult(self) -> Optional[PGresult]: return self._pgresult @pgresult.setter - def pgresult(self, result: Optional["pq.proto.PGresult"]) -> None: + def pgresult(self, result: Optional[PGresult]) -> None: self._pgresult = result if result is None: