]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Rename adapt.Format to PyFormat
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 10 Jul 2021 15:42:30 +0000 (17:42 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 10 Jul 2021 17:08:15 +0000 (19:08 +0200)
36 files changed:
docs/advanced/adapt.rst
psycopg/psycopg/_enums.py
psycopg/psycopg/_queries.py
psycopg/psycopg/_transform.py
psycopg/psycopg/adapt.py
psycopg/psycopg/copy.py
psycopg/psycopg/proto.py
psycopg/psycopg/sql.py
psycopg/psycopg/types/array.py
psycopg/psycopg/types/composite.py
psycopg/psycopg/types/datetime.py
psycopg/psycopg/types/numeric.py
psycopg/psycopg/types/range.py
psycopg_c/psycopg_c/_psycopg.pyi
psycopg_c/psycopg_c/_psycopg.pyx
psycopg_c/psycopg_c/_psycopg/transform.pyx
tests/fix_faker.py
tests/test_adapt.py
tests/test_copy.py
tests/test_copy_async.py
tests/test_cursor.py
tests/test_cursor_async.py
tests/test_query.py
tests/test_sql.py
tests/types/test_array.py
tests/types/test_bool.py
tests/types/test_composite.py
tests/types/test_datetime.py
tests/types/test_json.py
tests/types/test_net.py
tests/types/test_none.py
tests/types/test_numeric.py
tests/types/test_range.py
tests/types/test_string.py
tests/types/test_uuid.py
tests/typing_example.py

index 6958132f7ed40b57e934c03b88d631442ecb9739..e24dcc615ddae539a17fc43f93c760317ef9372e 100644 (file)
@@ -133,7 +133,7 @@ right instance.
   :sql:`integer`, :sql:`bigint`, :sql:`smallint` according to its value).
 
 - According to the placeholder used (``%s``, ``%b``, ``%t``), Psycopg may
-  pick a binary or a text dumper. When using the ``%s`` "`~Format.AUTO`"
+  pick a binary or a text dumper. When using the ``%s`` "`~PyFormat.AUTO`"
   format, if the same type has both a text and a binary dumper registered, the
   last one registered (using `Dumper.register()`) will be selected.
 
@@ -162,7 +162,7 @@ Objects involved in types adaptation
     move to API section
 
 
-.. autoclass:: Format
+.. autoclass:: PyFormat
     :members:
 
 
index d005202953def4c6631305f8c565fddce1d2c523..7ccc1d1e693df0b36f646091e375945de80653a8 100644 (file)
@@ -12,7 +12,7 @@ from enum import Enum
 from . import pq
 
 
-class Format(str, Enum):
+class PyFormat(str, Enum):
     """
     Enum representing the format wanted for a query argument.
 
@@ -30,20 +30,20 @@ class Format(str, Enum):
     """Binary parameter (``%b`` placeholder)."""
 
     @classmethod
-    def from_pq(cls, fmt: pq.Format) -> "Format":
+    def from_pq(cls, fmt: pq.Format) -> "PyFormat":
         return _pg2py[fmt]
 
     @classmethod
-    def as_pq(cls, fmt: "Format") -> pq.Format:
+    def as_pq(cls, fmt: "PyFormat") -> pq.Format:
         return _py2pg[fmt]
 
 
 _py2pg = {
-    Format.TEXT: pq.Format.TEXT,
-    Format.BINARY: pq.Format.BINARY,
+    PyFormat.TEXT: pq.Format.TEXT,
+    PyFormat.BINARY: pq.Format.BINARY,
 }
 
 _pg2py = {
-    pq.Format.TEXT: Format.TEXT,
-    pq.Format.BINARY: Format.BINARY,
+    pq.Format.TEXT: PyFormat.TEXT,
+    pq.Format.BINARY: PyFormat.BINARY,
 }
index 06ca2640c93d5b8c6f149027b1f2f844d43ed8e5..4732c1fee772271e4cd2e6098da74214a9dcaee2 100644 (file)
@@ -13,7 +13,7 @@ from . import pq
 from . import errors as e
 from .sql import Composable
 from .proto import Query, Params
-from ._enums import Format
+from ._enums import PyFormat
 
 if TYPE_CHECKING:
     from .proto import Transformer
@@ -22,7 +22,7 @@ if TYPE_CHECKING:
 class QueryPart(NamedTuple):
     pre: bytes
     item: Union[int, str]
-    format: Format
+    format: PyFormat
 
 
 class PostgresQuery:
@@ -43,7 +43,7 @@ class PostgresQuery:
         self.types: Tuple[int, ...] = ()
 
         # The format requested by the user and the ones to really pass Postgres
-        self._want_formats: Optional[List[Format]] = None
+        self._want_formats: Optional[List[PyFormat]] = None
         self.formats: Optional[Sequence[pq.Format]] = None
 
         self._parts: List[QueryPart]
@@ -103,7 +103,7 @@ class PostgresQuery:
 @lru_cache()
 def _query2pg(
     query: Union[bytes, str], encoding: str
-) -> Tuple[bytes, List[Format], Optional[List[str]], List[QueryPart]]:
+) -> Tuple[bytes, List[PyFormat], Optional[List[str]], List[QueryPart]]:
     """
     Convert Python query and params into something Postgres understands.
 
@@ -136,7 +136,7 @@ def _query2pg(
             formats.append(part.format)
 
     elif isinstance(parts[0].item, str):
-        seen: Dict[str, Tuple[bytes, Format]] = {}
+        seen: Dict[str, Tuple[bytes, PyFormat]] = {}
         order = []
         for part in parts[:-1]:
             assert isinstance(part.item, str)
@@ -250,7 +250,7 @@ def _split_query(query: bytes, encoding: str = "ascii") -> List[QueryPart]:
         pre, m = parts[i]
         if m is None:
             # last part
-            rv.append(QueryPart(pre, 0, Format.AUTO))
+            rv.append(QueryPart(pre, 0, PyFormat.AUTO))
             break
 
         ph = m.group(0)
@@ -297,7 +297,7 @@ def _split_query(query: bytes, encoding: str = "ascii") -> List[QueryPart]:
 
 
 _ph_to_fmt = {
-    b"s": Format.AUTO,
-    b"t": Format.TEXT,
-    b"b": Format.BINARY,
+    b"s": PyFormat.AUTO,
+    b"t": PyFormat.TEXT,
+    b"b": PyFormat.BINARY,
 }
index 00f1d555bbc2947443e811b2d6c65462fa789916..1d472380843432f5039de60ac911ea0a7bfe3f10 100644 (file)
@@ -12,8 +12,7 @@ from . import pq
 from . import errors as e
 from .oids import INVALID_OID
 from .rows import Row, RowMaker
-from .proto import LoadFunc, AdaptContext
-from ._enums import Format
+from .proto import LoadFunc, AdaptContext, PyFormat
 
 if TYPE_CHECKING:
     from .pq.proto import PGresult
@@ -54,7 +53,7 @@ class Transformer(AdaptContext):
             self._conn = None
 
         # mapping class, fmt -> Dumper instance
-        self._dumpers_cache: DefaultDict[Format, DumperCache] = defaultdict(
+        self._dumpers_cache: DefaultDict[PyFormat, DumperCache] = defaultdict(
             dict
         )
 
@@ -112,7 +111,7 @@ class Transformer(AdaptContext):
         self._row_loaders = rc
 
     def dump_sequence(
-        self, params: Sequence[Any], formats: Sequence[Format]
+        self, params: Sequence[Any], formats: Sequence[PyFormat]
     ) -> Tuple[List[Any], Tuple[int, ...], Sequence[pq.Format]]:
         ps: List[Optional[bytes]] = [None] * len(params)
         ts = [INVALID_OID] * len(params)
@@ -134,7 +133,7 @@ class Transformer(AdaptContext):
 
         return ps, tuple(ts), fs
 
-    def get_dumper(self, obj: Any, format: Format) -> "Dumper":
+    def get_dumper(self, obj: Any, format: PyFormat) -> "Dumper":
         """
         Return a Dumper instance to dump *obj*.
         """
index ea2d78c5967950a069677afd2daf522a4ee89cbf..f6b1c46d32887943bead9e904ede4496da9656bd 100644 (file)
@@ -10,7 +10,7 @@ from typing import cast, TYPE_CHECKING, TypeVar
 
 from . import pq
 from . import errors as e
-from ._enums import Format as Format
+from ._enums import PyFormat as PyFormat
 from .oids import postgres_types
 from .proto import AdaptContext, Buffer as Buffer
 from ._cmodule import _psycopg
@@ -60,7 +60,7 @@ class Dumper(ABC):
             return b"'%s'" % esc.escape_string(value)
 
     def get_key(
-        self, obj: Any, format: Format
+        self, obj: Any, format: PyFormat
     ) -> Union[type, Tuple[type, ...]]:
         """Return an alternative key to upgrade the dumper to represent *obj*
 
@@ -80,7 +80,7 @@ class Dumper(ABC):
         """
         return self.cls
 
-    def upgrade(self, obj: Any, format: Format) -> "Dumper":
+    def upgrade(self, obj: Any, format: PyFormat) -> "Dumper":
         """Return a new dumper to manage *obj*.
 
         Once `Transformer.get_dumper()` has been notified that this Dumper
@@ -140,7 +140,7 @@ class AdaptersMap(AdaptContext):
     is cheap: a copy is made only on customisation.
     """
 
-    _dumpers: Dict[Format, Dict[Union[type, str], Type["proto.Dumper"]]]
+    _dumpers: Dict[PyFormat, Dict[Union[type, str], Type["proto.Dumper"]]]
     _loaders: List[Dict[int, Type["Loader"]]]
     types: TypesRegistry
 
@@ -161,7 +161,7 @@ class AdaptersMap(AdaptContext):
             template._own_loaders = [False, False]
             self.types = TypesRegistry(template.types)
         else:
-            self._dumpers = {fmt: {} for fmt in Format}
+            self._dumpers = {fmt: {} for fmt in PyFormat}
             self._own_dumpers = _dumpers_owned.copy()
             self._loaders = [{}, {}]
             self._own_loaders = [True, True]
@@ -192,7 +192,7 @@ class AdaptersMap(AdaptContext):
 
         # Register the dumper both as its format and as auto
         # so that the last dumper registered is used in auto (%s) format
-        for fmt in (Format.from_pq(dumper.format), Format.AUTO):
+        for fmt in (PyFormat.from_pq(dumper.format), PyFormat.AUTO):
             if not self._own_dumpers[fmt]:
                 self._dumpers[fmt] = self._dumpers[fmt].copy()
                 self._own_dumpers[fmt] = True
@@ -222,7 +222,7 @@ class AdaptersMap(AdaptContext):
 
         self._loaders[fmt][oid] = loader
 
-    def get_dumper(self, cls: type, format: Format) -> Type["proto.Dumper"]:
+    def get_dumper(self, cls: type, format: PyFormat) -> Type["proto.Dumper"]:
         """
         Return the dumper class for the given type and format.
 
@@ -247,7 +247,7 @@ class AdaptersMap(AdaptContext):
 
         raise e.ProgrammingError(
             f"cannot adapt type {cls.__name__}"
-            f" to format {Format(format).name}"
+            f" to format {PyFormat(format).name}"
         )
 
     def get_loader(
@@ -285,8 +285,8 @@ class AdaptersMap(AdaptContext):
         return cls
 
 
-_dumpers_owned = dict.fromkeys(Format, True)
-_dumpers_shared = dict.fromkeys(Format, False)
+_dumpers_owned = dict.fromkeys(PyFormat, True)
+_dumpers_shared = dict.fromkeys(PyFormat, False)
 
 global_adapters = AdaptersMap(types=postgres_types)
 
index f258be088914d5e68cc72891bc7a2d491849af98..5829189bdfb228e1178b0a2028fb71b4fa1d235a 100644 (file)
@@ -17,7 +17,7 @@ from typing import Any, Dict, List, Match, Optional, Sequence, Type, Tuple
 from . import pq
 from . import errors as e
 from .pq import ExecStatus
-from .adapt import Format
+from .adapt import PyFormat
 from .proto import ConnectionType, PQGen, Transformer
 from .compat import create_task
 from ._cmodule import _psycopg
@@ -541,7 +541,7 @@ def _format_row_text(
 
     for item in row:
         if item is not None:
-            dumper = tx.get_dumper(item, Format.TEXT)
+            dumper = tx.get_dumper(item, PyFormat.TEXT)
             b = dumper.dump(item)
             out += _dump_re.sub(_dump_sub, b)
         else:
@@ -562,7 +562,7 @@ def _format_row_binary(
     out += _pack_int2(len(row))
     for item in row:
         if item is not None:
-            dumper = tx.get_dumper(item, Format.BINARY)
+            dumper = tx.get_dumper(item, PyFormat.BINARY)
             b = dumper.dump(item)
             out += _pack_int4(len(b))
             out += b
index 8c96ff07b68269adea97c91ee91b91825a86a312..8c1b574feedc49c3368290e90ed0711c1e7f0982 100644 (file)
@@ -9,7 +9,7 @@ from typing import List, Optional, Sequence, Tuple, TypeVar, Union
 from typing import TYPE_CHECKING
 
 from . import pq
-from . import _enums
+from ._enums import PyFormat as PyFormat
 from .compat import Protocol
 
 if TYPE_CHECKING:
@@ -22,9 +22,6 @@ if TYPE_CHECKING:
     from .waiting import Wait, Ready
     from .connection import BaseConnection
 
-# NOMERGE: change name of _enums.Format
-PyFormat = _enums.Format
-
 # An object implementing the buffer protocol
 Buffer = Union[bytes, bytearray, memoryview]
 
index 24e26c628dc992d487cb1c72eec3b09ef3958906..740c35dcb38d8899495ed022652891ebc79ec66e 100644 (file)
@@ -10,7 +10,7 @@ from abc import ABC, abstractmethod
 from typing import Any, Iterator, List, Optional, Sequence, Union
 
 from .pq import Escaping
-from .adapt import Transformer, Format
+from .adapt import Transformer, PyFormat
 from .proto import AdaptContext
 
 
@@ -395,7 +395,7 @@ class Literal(Composable):
 
     def as_bytes(self, context: Optional[AdaptContext]) -> bytes:
         tx = Transformer(context)
-        dumper = tx.get_dumper(self._obj, Format.TEXT)
+        dumper = tx.get_dumper(self._obj, PyFormat.TEXT)
         return dumper.quote(self._obj)
 
 
@@ -427,7 +427,7 @@ class Placeholder(Composable):
 
     """
 
-    def __init__(self, name: str = "", format: Format = Format.AUTO):
+    def __init__(self, name: str = "", format: PyFormat = PyFormat.AUTO):
         super().__init__(name)
         if not isinstance(name, str):
             raise TypeError(f"expected string as name, got {name!r}")
@@ -441,8 +441,8 @@ class Placeholder(Composable):
         parts = []
         if self._obj:
             parts.append(repr(self._obj))
-        if self._format != Format.AUTO:
-            parts.append(f"format={Format(self._format).name}")
+        if self._format != PyFormat.AUTO:
+            parts.append(f"format={PyFormat(self._format).name}")
 
         return f"{self.__class__.__name__}({', '.join(parts)})"
 
index b5dfe2c9f2af3d5c922a2ed981849daa33052c2c..ad998dae5e7bcd1a92f707cac8582878dcb814cf 100644 (file)
@@ -12,7 +12,7 @@ from typing import cast
 from .. import pq
 from .. import errors as e
 from ..oids import postgres_types, TEXT_OID, TEXT_ARRAY_OID, INVALID_OID
-from ..adapt import RecursiveDumper, RecursiveLoader, Format as Pg3Format
+from ..adapt import RecursiveDumper, RecursiveLoader, PyFormat
 from ..proto import Dumper, AdaptContext, Buffer
 from .._struct import pack_len, unpack_len
 from .._typeinfo import TypeInfo
@@ -35,7 +35,7 @@ class BaseListDumper(RecursiveDumper):
         self.sub_dumper: Optional[Dumper] = None
         self._types = context.adapters.types if context else postgres_types
 
-    def get_key(self, obj: List[Any], format: Pg3Format) -> Tuple[type, ...]:
+    def get_key(self, obj: List[Any], format: PyFormat) -> Tuple[type, ...]:
         item = self._find_list_element(obj)
         if item is not None:
             sd = self._tx.get_dumper(item, format)
@@ -43,7 +43,7 @@ class BaseListDumper(RecursiveDumper):
         else:
             return (self.cls,)
 
-    def upgrade(self, obj: List[Any], format: Pg3Format) -> "BaseListDumper":
+    def upgrade(self, obj: List[Any], format: PyFormat) -> "BaseListDumper":
         item = self._find_list_element(obj)
         if item is None:
             # Empty lists can only be dumped as text if the type is unknown.
index 07b3a2c9416ed722bc368e541c9756298bfd9232..b15ba06998bfb1632b1757c8156579d55016e404 100644 (file)
@@ -12,7 +12,7 @@ from typing import Sequence, Tuple, Type
 
 from .. import pq
 from ..oids import TEXT_OID
-from ..adapt import Format, RecursiveDumper, RecursiveLoader
+from ..adapt import PyFormat, RecursiveDumper, RecursiveLoader
 from ..proto import AdaptContext, Buffer
 from .._struct import unpack_len
 from .._typeinfo import CompositeInfo as CompositeInfo  # exported here
@@ -40,7 +40,7 @@ class SequenceDumper(RecursiveDumper):
                 parts.append(sep)
                 continue
 
-            dumper = self._tx.get_dumper(item, Format.from_pq(self.format))
+            dumper = self._tx.get_dumper(item, PyFormat.from_pq(self.format))
             ad = dumper.dump(item)
             if not ad:
                 ad = b'""'
index 3df7245ccedcfffcb6d5b6bb16d59507803d0e91..793001085aa46b94e1e1a6a87675e2563468d570 100644 (file)
@@ -13,7 +13,7 @@ from typing import Any, Callable, cast, Optional, Tuple, Union, TYPE_CHECKING
 from ..pq import Format
 from .._tz import get_tzinfo
 from ..oids import postgres_types as builtins
-from ..adapt import Buffer, Dumper, Loader, Format as Pg3Format
+from ..adapt import Buffer, Dumper, Loader, PyFormat
 from ..proto import AdaptContext
 from ..errors import InterfaceError, DataError
 from .._struct import pack_int4, pack_int8, unpack_int4, unpack_int8
@@ -62,9 +62,7 @@ class DateBinaryDumper(Dumper):
 
 
 class _BaseTimeDumper(Dumper):
-    def get_key(
-        self, obj: time, format: Pg3Format
-    ) -> Union[type, Tuple[type]]:
+    def get_key(self, obj: time, format: PyFormat) -> Union[type, Tuple[type]]:
         # Use (cls,) to report the need to upgrade to a dumper for timetz (the
         # Frankenstein of the data types).
         if not obj.tzinfo:
@@ -72,7 +70,7 @@ class _BaseTimeDumper(Dumper):
         else:
             return (self.cls,)
 
-    def upgrade(self, obj: time, format: Pg3Format) -> Dumper:
+    def upgrade(self, obj: time, format: PyFormat) -> Dumper:
         raise NotImplementedError
 
 
@@ -88,7 +86,7 @@ class TimeDumper(_BaseTimeTextDumper):
 
     _oid = builtins["time"].oid
 
-    def upgrade(self, obj: time, format: Pg3Format) -> Dumper:
+    def upgrade(self, obj: time, format: PyFormat) -> Dumper:
         if not obj.tzinfo:
             return self
         else:
@@ -111,7 +109,7 @@ class TimeBinaryDumper(_BaseTimeDumper):
         )
         return pack_int8(us)
 
-    def upgrade(self, obj: time, format: Pg3Format) -> Dumper:
+    def upgrade(self, obj: time, format: PyFormat) -> Dumper:
         if not obj.tzinfo:
             return self
         else:
@@ -134,7 +132,7 @@ class TimeTzBinaryDumper(_BaseTimeDumper):
 
 class _BaseDatetimeDumper(Dumper):
     def get_key(
-        self, obj: datetime, format: Pg3Format
+        self, obj: datetime, format: PyFormat
     ) -> Union[type, Tuple[type]]:
         # Use (cls,) to report the need to upgrade (downgrade, actually) to a
         # dumper for naive timestamp.
@@ -143,7 +141,7 @@ class _BaseDatetimeDumper(Dumper):
         else:
             return (self.cls,)
 
-    def upgrade(self, obj: datetime, format: Pg3Format) -> Dumper:
+    def upgrade(self, obj: datetime, format: PyFormat) -> Dumper:
         raise NotImplementedError
 
 
@@ -161,7 +159,7 @@ class DatetimeDumper(_BaseDatetimeTextDumper):
 
     _oid = builtins["timestamptz"].oid
 
-    def upgrade(self, obj: datetime, format: Pg3Format) -> Dumper:
+    def upgrade(self, obj: datetime, format: PyFormat) -> Dumper:
         if obj.tzinfo:
             return self
         else:
@@ -185,7 +183,7 @@ class DatetimeBinaryDumper(_BaseDatetimeDumper):
         )
         return pack_int8(micros)
 
-    def upgrade(self, obj: datetime, format: Pg3Format) -> Dumper:
+    def upgrade(self, obj: datetime, format: PyFormat) -> Dumper:
         if obj.tzinfo:
             return self
         else:
index 2d12af3fe767d6097e440ad193a7ee3519adde38..7a38e7dc1e478069ce6e31d247b57259fa9812b2 100644 (file)
@@ -12,8 +12,7 @@ from decimal import Decimal, DefaultContext, Context
 from .. import errors as e
 from ..pq import Format
 from ..oids import postgres_types as builtins
-from ..adapt import Buffer, Dumper, Loader
-from ..adapt import Format as Pg3Format
+from ..adapt import Buffer, Dumper, Loader, PyFormat
 from ..proto import AdaptContext
 from .._struct import pack_int2, pack_uint2, unpack_int2
 from .._struct import pack_int4, pack_uint4, unpack_int4, unpack_uint4
@@ -124,7 +123,7 @@ class IntDumper(Dumper):
             " dump() is not supposed to be called"
         )
 
-    def get_key(self, obj: int, format: Pg3Format) -> type:
+    def get_key(self, obj: int, format: PyFormat) -> type:
         return self.upgrade(obj, format).cls
 
     _int2_dumper = Int2Dumper(Int2)
@@ -132,7 +131,7 @@ class IntDumper(Dumper):
     _int8_dumper = Int8Dumper(Int8)
     _int_numeric_dumper = IntNumericDumper(IntNumeric)
 
-    def upgrade(self, obj: int, format: Pg3Format) -> Dumper:
+    def upgrade(self, obj: int, format: PyFormat) -> Dumper:
         if -(2 ** 31) <= obj < 2 ** 31:
             if -(2 ** 15) <= obj < 2 ** 15:
                 return self._int2_dumper
index a55954a23eb8e03b5493f5f0a1f13a88315f339c..00a624eacd605cc13706d4c57778f9fa7715d63e 100644 (file)
@@ -12,7 +12,7 @@ from datetime import date, datetime
 
 from ..pq import Format
 from ..oids import postgres_types as builtins, INVALID_OID
-from ..adapt import RecursiveDumper, RecursiveLoader, Format as Pg3Format
+from ..adapt import RecursiveDumper, RecursiveLoader, PyFormat
 from ..proto import Dumper, AdaptContext, Buffer
 from .._struct import pack_len, unpack_len
 from .._typeinfo import RangeInfo as RangeInfo  # exported here
@@ -257,10 +257,10 @@ class BaseRangeDumper(RecursiveDumper):
         super().__init__(cls, context)
         self.sub_dumper: Optional[Dumper] = None
         self._types = context.adapters.types if context else builtins
-        self._adapt_format = Pg3Format.from_pq(self.format)
+        self._adapt_format = PyFormat.from_pq(self.format)
 
     def get_key(
-        self, obj: Range[Any], format: Pg3Format
+        self, obj: Range[Any], format: PyFormat
     ) -> Union[type, Tuple[type, ...]]:
         # If we are a subclass whose oid is specified we don't need upgrade
         if self.oid != INVALID_OID:
@@ -273,7 +273,7 @@ class BaseRangeDumper(RecursiveDumper):
         else:
             return (self.cls,)
 
-    def upgrade(self, obj: Range[Any], format: Pg3Format) -> "BaseRangeDumper":
+    def upgrade(self, obj: Range[Any], format: PyFormat) -> "BaseRangeDumper":
         # If we are a subclass whose oid is specified we don't need upgrade
         if self.oid != INVALID_OID:
             return self
@@ -286,7 +286,7 @@ class BaseRangeDumper(RecursiveDumper):
         if type(item) is int:
             # postgres won't cast int4range -> int8range so we must use
             # text format and unknown oid here
-            sd = self._tx.get_dumper(item, Pg3Format.TEXT)
+            sd = self._tx.get_dumper(item, PyFormat.TEXT)
             dumper = RangeDumper(self.cls, self._tx)
             dumper.sub_dumper = sd
             dumper.oid = INVALID_OID
index 90b3728806a60667382a1e7c38506aeb6b529759..e5ba1ad1edcd2f1ef593e36611192d635179dc37 100644 (file)
@@ -12,7 +12,7 @@ from typing import Any, Iterable, List, Optional, Sequence, Tuple
 from psycopg import pq
 from psycopg import proto
 from psycopg.rows import Row, RowMaker
-from psycopg.adapt import  Loader, AdaptersMap, Format
+from psycopg.adapt import  Loader, AdaptersMap, PyFormat
 from psycopg.proto import Dumper
 from psycopg.pq.proto import PGconn, PGresult
 from psycopg.connection import BaseConnection
@@ -32,9 +32,9 @@ class Transformer(proto.AdaptContext):
         self, types: Sequence[int], formats: Sequence[pq.Format]
     ) -> None: ...
     def dump_sequence(
-        self, params: Sequence[Any], formats: Sequence[Format]
+        self, params: Sequence[Any], formats: Sequence[PyFormat]
     ) -> Tuple[List[Any], Tuple[int, ...], Sequence[pq.Format]]: ...
-    def get_dumper(self, obj: Any, format: Format) -> Dumper: ...
+    def get_dumper(self, obj: Any, format: PyFormat) -> Dumper: ...
     def load_rows(
         self, row0: int, row1: int, make_row: RowMaker[Row]
     ) -> List[Row]: ...
index 0c97f7904dc56d4cada731865d5655b6874201d7..298f9635b0510b63e5cd7560d36fffacd4b9b250 100644 (file)
@@ -12,14 +12,14 @@ from psycopg_c.pq cimport libpq
 from psycopg_c._psycopg cimport oids
 
 from psycopg.pq import Format as _pq_Format
-from psycopg._enums import Format as _pg_Format
+from psycopg._enums import PyFormat as _py_Format
 
 PQ_TEXT = _pq_Format.TEXT
 PQ_BINARY = _pq_Format.BINARY
 
-PG_AUTO = _pg_Format.AUTO
-PG_TEXT = _pg_Format.TEXT
-PG_BINARY = _pg_Format.BINARY
+PG_AUTO = _py_Format.AUTO
+PG_TEXT = _py_Format.TEXT
+PG_BINARY = _py_Format.BINARY
 
 
 include "_psycopg/adapt.pyx"
index 4fdc48022a343ddb1a330836b058c7c692e2b638..61976b375c82d34ad6d3375cef45b94ba9969289 100644 (file)
@@ -22,7 +22,6 @@ from cpython.object cimport PyObject, PyObject_CallFunctionObjArgs
 from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple
 
 from psycopg import errors as e
-from psycopg._enums import Format as Pg3Format
 from psycopg.pq import Format as PqFormat
 from psycopg.rows import Row, RowMaker
 
index 300786f90f0e132999dcd63bbe4010c45dc52cc1..d04e8669955a3b1c7a03313b650d9b6a73148ebe 100644 (file)
@@ -11,7 +11,7 @@ import pytest
 
 import psycopg
 from psycopg import sql
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat
 from psycopg.types.range import Range
 from psycopg.types.numeric import Int4, Int8
 
@@ -34,7 +34,7 @@ class Faker:
 
     def __init__(self, connection):
         self.conn = connection
-        self._format = Format.BINARY
+        self._format = PyFormat.BINARY
         self.records = []
 
         self._schema = None
@@ -429,14 +429,18 @@ class Faker:
             (dt.datetime, False),
         ]
         # TODO: learn to dump numeric ranges in binary
-        if self.format != Format.BINARY:
+        if self.format != PyFormat.BINARY:
             subtypes.extend([Int4, Int8])
 
         return (cls, choice(subtypes))
 
     def make_Range(self, spec):
         # TODO: drop format check after fixing binary dumping of empty ranges
-        if random() < 0.02 and spec[0] is Range and self.format == Format.TEXT:
+        if (
+            random() < 0.02
+            and spec[0] is Range
+            and self.format == PyFormat.TEXT
+        ):
             return spec[0](empty=True)
 
         while True:
@@ -459,7 +463,7 @@ class Faker:
 
             # avoid generating ranges with no type info if dumping in binary
             # TODO: lift this limitation after test_copy_in_empty xfail is fixed
-            if spec[0] is Range and self.format == Format.BINARY:
+            if spec[0] is Range and self.format == PyFormat.BINARY:
                 if bounds[0] is bounds[1] is None:
                     continue
 
index 4f60228c7f88f2f8a921e472850b5c4e5928c850..caf14d48e7e4ca990fdc83f8fc7eb83863ac2f16 100644 (file)
@@ -5,7 +5,7 @@ import pytest
 
 import psycopg
 from psycopg import pq, sql
-from psycopg.adapt import Transformer, Format, Dumper, Loader
+from psycopg.adapt import Transformer, PyFormat as Format, Dumper, Loader
 from psycopg.oids import postgres_types as builtins, TEXT_OID
 from psycopg._cmodule import _psycopg
 
index dabb8aafb91e47286d7595f2111df65062462cef..8e0fafbafa8bdc66dc8c0e253b82d6e137f3e3ae 100644 (file)
@@ -11,7 +11,7 @@ from psycopg import pq
 from psycopg import sql
 from psycopg import errors as e
 from psycopg.pq import Format
-from psycopg.adapt import Format as PgFormat
+from psycopg.adapt import PyFormat as PgFormat
 from psycopg.types.numeric import Int4
 
 from .utils import gc_collect
index e0f7ce9e162f1901d4ead593bdeca388325f4925..8a512a73d2dcabe937ac18b2e5cdff8db737838e 100644 (file)
@@ -11,7 +11,7 @@ from psycopg import pq
 from psycopg import sql
 from psycopg import errors as e
 from psycopg.pq import Format
-from psycopg.adapt import Format as PgFormat
+from psycopg.adapt import PyFormat as PgFormat
 
 from .utils import gc_collect
 from .test_copy import sample_text, sample_binary, sample_binary_rows  # noqa
index e575867fd7b12423cee3be40aa8f0e569ee7f10e..729a6ccfe5437a095c311069e5d928acbf873eb8 100644 (file)
@@ -8,7 +8,7 @@ import pytest
 import psycopg
 from psycopg import pq, sql, rows
 from psycopg.oids import postgres_types as builtins
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 
 from .utils import gc_collect
 
index 9d80b269884e8a8e844c6933e32e73d1d5eecd37..965d99894110233c5782128d5b92e129d3f913bb 100644 (file)
@@ -5,7 +5,7 @@ import datetime as dt
 
 import psycopg
 from psycopg import pq, sql, rows
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 
 from .utils import gc_collect
 from .test_cursor import my_row_factory
index 12ac37e48563a761d61523d407e39a7fd9e39373..0314dd8cf64f179b03b458d8cd6a66031cfce4a6 100644 (file)
@@ -2,7 +2,7 @@ import pytest
 
 import psycopg
 from psycopg import pq
-from psycopg.adapt import Transformer, Format
+from psycopg.adapt import Transformer, PyFormat as Format
 from psycopg._queries import PostgresQuery, _split_query
 
 
index 6813173d96cfe1e5f6db5c1756270790413c3e18..2232b336ae44a901fd3eef1c0b3a1164388d08c7 100644 (file)
@@ -8,7 +8,7 @@ import datetime as dt
 import pytest
 
 from psycopg import sql, ProgrammingError
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 
 
 @pytest.mark.parametrize(
index b04b752378ce535037aa19aa1709d6823078f72d..45fed9530eaef9d7aee4957324760e1d3794c56b 100644 (file)
@@ -3,7 +3,7 @@ import psycopg
 from psycopg import pq
 from psycopg import sql
 from psycopg.oids import postgres_types as builtins
-from psycopg.adapt import Format, Transformer
+from psycopg.adapt import PyFormat as Format, Transformer
 from psycopg.types import TypeInfo
 
 
index e8c3ba0acd6fcb90b379f060dab41b9646fe8e0c..04fd618863cf1729f92fe400d50ee32e3a2b491c 100644 (file)
@@ -3,7 +3,7 @@ import pytest
 from psycopg import pq
 from psycopg import sql
 from psycopg.oids import postgres_types as builtins
-from psycopg.adapt import Transformer, Format
+from psycopg.adapt import Transformer, PyFormat as Format
 
 
 @pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
index 4cbaa47dce0b2916174d1cbc7449c8de94b164bd..621309dfc04921c8cf08fe988366eb26d693953c 100644 (file)
@@ -3,7 +3,7 @@ import pytest
 from psycopg import pq
 from psycopg.sql import Identifier
 from psycopg.oids import postgres_types as builtins
-from psycopg.adapt import Format, global_adapters
+from psycopg.adapt import PyFormat as Format, global_adapters
 from psycopg.types.composite import CompositeInfo
 
 
index 2e91a79b2dbbf656ffe543bf6e4ab869d0a8ab09..1b4c62abe1916ab09c87ced6482c3d8888a7915f 100644 (file)
@@ -4,7 +4,7 @@ import datetime as dt
 import pytest
 
 from psycopg import DataError, pq, sql
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 
 
 class TestDate:
index d273babbee915714508ab85ecb19c247a46d15da..2b2bfe79f23ec704d3b7aa6a4d83a9a32e1baf25 100644 (file)
@@ -6,7 +6,7 @@ import pytest
 import psycopg.types
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 from psycopg.types.json import Json, Jsonb, set_json_dumps, set_json_loads
 
 samples = [
index 38058774ad2e250dc4cc0405036821f2f66eec7a..154c74da02fba5c4893561eee8b6b53968ec0734 100644 (file)
@@ -6,7 +6,7 @@ import pytest
 
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 
 
 @pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
index 87f731e05fb257b867f1028c73da9fd48ab545a3..fd12f278fcabda5b7e402b73b9ca10559a3716d3 100644 (file)
@@ -1,5 +1,5 @@
 from psycopg import sql
-from psycopg.adapt import Transformer, Format
+from psycopg.adapt import Transformer, PyFormat as Format
 
 
 def test_quote_none(conn):
index db68c5df5f37603d32a5eb092083a7721ba11263..16e98cbe8fe018a924ece09a0c08f0b953af067c 100644 (file)
@@ -5,7 +5,7 @@ import pytest
 
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import Transformer, Format
+from psycopg.adapt import Transformer, PyFormat as Format
 from psycopg.types.numeric import FloatLoader
 
 
index 9ef9d93f8de1bd4b097910097658eb8bd3bf30b5..634aadc1507dc87f2516fae7c28cb390fbf5f9e2 100644 (file)
@@ -7,7 +7,7 @@ import pytest
 import psycopg.errors
 from psycopg import pq
 from psycopg.sql import Identifier
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 from psycopg.types.range import Range, RangeInfo
 
 
index 33624b71edf907976414e9fbcaa87150f1ee386a..04669f0fc94839a9a88b5055b72cc126d840232d 100644 (file)
@@ -3,7 +3,7 @@ import pytest
 import psycopg
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 from psycopg import Binary
 
 eur = "\u20ac"
index 81db48ba8eb8e91be8ef829336d68b49cf028763..34d5d08edc8bcb7af2e845491295b0cc4db7861e 100644 (file)
@@ -6,7 +6,7 @@ import pytest
 
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import Format
+from psycopg.adapt import PyFormat as Format
 
 
 @pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
index ad4931355692b87160fb4417738df8e3b9483f0a..7e3d6cf09bf61a6b605895fbe29a7d3518728085 100644 (file)
@@ -6,8 +6,8 @@ from dataclasses import dataclass
 from typing import Any, Callable, Optional, Sequence, Tuple
 
 from psycopg import AnyCursor, Connection, Cursor, ServerCursor, connect
-from psycopg import pq, adapt
-from psycopg.proto import Dumper, AdaptContext
+from psycopg import pq
+from psycopg.proto import Dumper, AdaptContext, PyFormat
 
 
 def int_row_factory(cursor: AnyCursor[int]) -> Callable[[Sequence[int]], int]:
@@ -110,8 +110,8 @@ class MyStrDumper:
         esc = pq.Escaping()
         return b"'%s'" % esc.escape_string(value.replace(b"h", b"q"))
 
-    def get_key(self, obj: str, format: adapt.Format) -> type:
+    def get_key(self, obj: str, format: PyFormat) -> type:
         return self.cls
 
-    def upgrade(self, obj: str, format: adapt.Format) -> "MyStrDumper":
+    def upgrade(self, obj: str, format: PyFormat) -> "MyStrDumper":
         return self