]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: drop use of typing.Tuple
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 30 May 2024 01:34:17 +0000 (03:34 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 4 Jun 2024 14:52:16 +0000 (16:52 +0200)
38 files changed:
psycopg/psycopg/_connection_base.py
psycopg/psycopg/_copy.py
psycopg/psycopg/_copy_async.py
psycopg/psycopg/_copy_base.py
psycopg/psycopg/_cursor_base.py
psycopg/psycopg/_pipeline.py
psycopg/psycopg/_preparing.py
psycopg/psycopg/_py_transformer.py
psycopg/psycopg/_queries.py
psycopg/psycopg/_struct.py
psycopg/psycopg/abc.py
psycopg/psycopg/client_cursor.py
psycopg/psycopg/errors.py
psycopg/psycopg/pq/_pq_ctypes.py
psycopg/psycopg/pq/abc.py
psycopg/psycopg/pq/pq_ctypes.py
psycopg/psycopg/rows.py
psycopg/psycopg/types/array.py
psycopg/psycopg/types/composite.py
psycopg/psycopg/types/datetime.py
psycopg/psycopg/types/enum.py
psycopg/psycopg/types/json.py
psycopg/psycopg/types/numeric.py
psycopg/psycopg/types/range.py
psycopg_c/psycopg_c/_psycopg.pyi
psycopg_c/psycopg_c/_psycopg/copy.pyx
psycopg_c/psycopg_c/_psycopg/transform.pyx
psycopg_c/psycopg_c/pq/pgconn.pyx
psycopg_pool/psycopg_pool/base.py
tests/fix_faker.py
tests/fix_gc.py
tests/pool/test_pool.py
tests/pool/test_pool_async.py
tests/pool/test_pool_common.py
tests/pool/test_pool_common_async.py
tests/scripts/pipeline-demo.py
tests/typing_example.py
tests/utils.py

index 98eda8a747caef390c1ce5c3e403e3ce6fe58336..691969b819d94182704f80f229d595d50badbe59 100644 (file)
@@ -8,7 +8,7 @@ from __future__ import annotations
 
 import sys
 import logging
-from typing import Callable, Generic, NamedTuple, Tuple, TYPE_CHECKING
+from typing import Callable, Generic, NamedTuple, TYPE_CHECKING
 from weakref import ref, ReferenceType
 from warnings import warn
 from functools import partial
@@ -114,7 +114,7 @@ class BaseConnection(Generic[Row]):
 
         self._closed = False  # closed by an explicit close()
         self._prepared: PrepareManager = PrepareManager()
-        self._tpc: Tuple[Xid, bool] | None = None  # xid, prepared
+        self._tpc: tuple[Xid, bool] | None = None  # xid, prepared
 
         wself = ref(self)
         pgconn.notice_handler = partial(BaseConnection._notice_handler, wself)
index 7cbd9885318c898109d3ed32380059e31a96aea0..1c393a9d632925f4ab4079930a3683d0b071bfef 100644 (file)
@@ -11,7 +11,7 @@ from __future__ import annotations
 
 from abc import ABC, abstractmethod
 from types import TracebackType
-from typing import Any, Iterator, Tuple, Sequence, TYPE_CHECKING
+from typing import Any, Iterator, Sequence, TYPE_CHECKING
 
 from . import pq
 from . import errors as e
@@ -95,7 +95,7 @@ class Copy(BaseCopy["Connection[Any]"]):
         """
         return self.connection.wait(self._read_gen())
 
-    def rows(self) -> Iterator[Tuple[Any, ...]]:
+    def rows(self) -> Iterator[tuple[Any, ...]]:
         """
         Iterate on the result of a :sql:`COPY TO` operation record by record.
 
@@ -108,7 +108,7 @@ class Copy(BaseCopy["Connection[Any]"]):
                 break
             yield record
 
-    def read_row(self) -> Tuple[Any, ...] | None:
+    def read_row(self) -> tuple[Any, ...] | None:
         """
         Read a parsed row of data from a table after a :sql:`COPY TO` operation.
 
index 8f39005426b0fa77ea8c2f5badffdc770c01b038..2c630da9b96d7b12d7c56d46f660e4de41b521dd 100644 (file)
@@ -8,7 +8,7 @@ from __future__ import annotations
 
 from abc import ABC, abstractmethod
 from types import TracebackType
-from typing import Any, AsyncIterator, Tuple, Sequence, TYPE_CHECKING
+from typing import Any, AsyncIterator, Sequence, TYPE_CHECKING
 
 from . import pq
 from . import errors as e
@@ -92,7 +92,7 @@ class AsyncCopy(BaseCopy["AsyncConnection[Any]"]):
         """
         return await self.connection.wait(self._read_gen())
 
-    async def rows(self) -> AsyncIterator[Tuple[Any, ...]]:
+    async def rows(self) -> AsyncIterator[tuple[Any, ...]]:
         """
         Iterate on the result of a :sql:`COPY TO` operation record by record.
 
@@ -105,7 +105,7 @@ class AsyncCopy(BaseCopy["AsyncConnection[Any]"]):
                 break
             yield record
 
-    async def read_row(self) -> Tuple[Any, ...] | None:
+    async def read_row(self) -> tuple[Any, ...] | None:
         """
         Read a parsed row of data from a table after a :sql:`COPY TO` operation.
 
index 2ae2c5502f4365d1fd06fb60261d5ea21ba403cc..354b589e49708dfd6627f4ed44e484fc16bb40ee 100644 (file)
@@ -10,7 +10,7 @@ import re
 import sys
 import struct
 from abc import ABC, abstractmethod
-from typing import Any, Generic, Match, Sequence, Tuple, TYPE_CHECKING
+from typing import Any, Generic, Match, Sequence, TYPE_CHECKING
 
 from . import pq
 from . import adapt
@@ -164,7 +164,7 @@ class BaseCopy(Generic[ConnectionType]):
         self.cursor._rowcount = nrows if nrows is not None else -1
         return memoryview(b"")
 
-    def _read_row_gen(self) -> PQGen[Tuple[Any, ...] | None]:
+    def _read_row_gen(self) -> PQGen[tuple[Any, ...] | None]:
         data = yield from self._read_gen()
         if not data:
             return None
@@ -199,7 +199,7 @@ class Formatter(ABC):
         self._row_mode = False  # true if the user is using write_row()
 
     @abstractmethod
-    def parse_row(self, data: Buffer) -> Tuple[Any, ...] | None: ...
+    def parse_row(self, data: Buffer) -> tuple[Any, ...] | None: ...
 
     @abstractmethod
     def write(self, buffer: Buffer | str) -> Buffer: ...
@@ -218,7 +218,7 @@ class TextFormatter(Formatter):
         super().__init__(transformer)
         self._encoding = encoding
 
-    def parse_row(self, data: Buffer) -> Tuple[Any, ...] | None:
+    def parse_row(self, data: Buffer) -> tuple[Any, ...] | None:
         if data:
             return parse_row_text(data, self.transformer)
         else:
@@ -262,7 +262,7 @@ class BinaryFormatter(Formatter):
         super().__init__(transformer)
         self._signature_sent = False
 
-    def parse_row(self, data: Buffer) -> Tuple[Any, ...] | None:
+    def parse_row(self, data: Buffer) -> tuple[Any, ...] | None:
         if not self._signature_sent:
             if data[: len(_binary_signature)] != _binary_signature:
                 raise e.DataError(
@@ -365,7 +365,7 @@ def _format_row_binary(
     return out
 
 
-def _parse_row_text(data: Buffer, tx: Transformer) -> Tuple[Any, ...]:
+def _parse_row_text(data: Buffer, tx: Transformer) -> tuple[Any, ...]:
     if not isinstance(data, bytes):
         data = bytes(data)
     fields = data.split(b"\t")
@@ -374,7 +374,7 @@ def _parse_row_text(data: Buffer, tx: Transformer) -> Tuple[Any, ...]:
     return tx.load_sequence(row)
 
 
-def _parse_row_binary(data: Buffer, tx: Transformer) -> Tuple[Any, ...]:
+def _parse_row_binary(data: Buffer, tx: Transformer) -> tuple[Any, ...]:
     row: list[Buffer | None] = []
     nfields = _unpack_int2(data, 0)[0]
     pos = 2
index 3da9ce5b414072f96595c2c172942f708e7fa527..6fb08dcfa8ac9948416276f944425306caedd2fc 100644 (file)
@@ -7,7 +7,7 @@ Psycopg BaseCursor object
 from __future__ import annotations
 
 from functools import partial
-from typing import Any, Generic, Iterable, NoReturn, Sequence, Tuple
+from typing import Any, Generic, Iterable, NoReturn, Sequence
 from typing import TYPE_CHECKING
 
 from . import pq
@@ -306,7 +306,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
 
     def _get_prepared(
         self, pgq: PostgresQuery, prepare: bool | None = None
-    ) -> Tuple[Prepare, bytes]:
+    ) -> tuple[Prepare, bytes]:
         return self._conn._prepared.get(pgq, prepare)
 
     def _stream_send_gen(
index 3f4ad769dd7d7974b008da390d6ac3d694b01fc9..239b619b562c96a08ccb440d61be07541c500788 100644 (file)
@@ -8,7 +8,7 @@ from __future__ import annotations
 
 import logging
 from types import TracebackType
-from typing import Any, Tuple, TYPE_CHECKING
+from typing import Any, TYPE_CHECKING
 
 from . import pq
 from . import errors as e
@@ -29,7 +29,7 @@ if TYPE_CHECKING:
 
 
 PendingResult: TypeAlias = (
-    Tuple["BaseCursor[Any, Any]", Tuple[Key, Prepare, bytes] | None] | None
+    tuple[BaseCursor[Any, Any], tuple[Key, Prepare, bytes] | None] | None
 )
 
 FATAL_ERROR = pq.ExecStatus.FATAL_ERROR
index 9c017e73e9157ba0677ad50e9b9a53435daf066c..eccf260de1a83271be69d85a59e95340a8d21da2 100644 (file)
@@ -7,7 +7,7 @@ Support for prepared statements
 from __future__ import annotations
 
 from enum import IntEnum, auto
-from typing import Sequence, Tuple, TYPE_CHECKING
+from typing import Sequence, TYPE_CHECKING
 from collections import OrderedDict
 
 from . import pq
@@ -20,7 +20,7 @@ if TYPE_CHECKING:
     from .pq.abc import PGresult
     from ._connection_base import BaseConnection
 
-Key: TypeAlias = Tuple[bytes, Tuple[int, ...]]
+Key: TypeAlias = tuple[bytes, tuple[int, ...]]
 
 COMMAND_OK = pq.ExecStatus.COMMAND_OK
 TUPLES_OK = pq.ExecStatus.TUPLES_OK
@@ -57,7 +57,7 @@ class PrepareManager:
 
     def get(
         self, query: PostgresQuery, prepare: bool | None = None
-    ) -> Tuple[Prepare, bytes]:
+    ) -> tuple[Prepare, bytes]:
         """
         Check if a query is prepared, tell back whether to prepare it.
         """
index 260d8d30ce1cb79eb7ca4a4319a629c9a471bcd7..3a1c2e5ab03533cc886e1122067d53355271dfa7 100644 (file)
@@ -11,7 +11,7 @@ dependencies problems).
 
 from __future__ import annotations
 
-from typing import Any, Sequence, Tuple, DefaultDict, TYPE_CHECKING
+from typing import Any, Sequence, DefaultDict, TYPE_CHECKING
 from collections import defaultdict
 
 from . import pq
@@ -55,7 +55,7 @@ class Transformer(AdaptContext):
         _oid_dumpers _oid_types _row_dumpers _row_loaders
         """.split()
 
-    types: Tuple[int, ...] | None
+    types: tuple[int, ...] | None
     formats: list[pq.Format] | None
 
     _adapters: "AdaptersMap"
@@ -81,11 +81,11 @@ class Transformer(AdaptContext):
 
         # mapping fmt, oid -> Dumper instance
         # Not often used, so create it only if needed.
-        self._oid_dumpers: Tuple[OidDumperCache, OidDumperCache] | None
+        self._oid_dumpers: tuple[OidDumperCache, OidDumperCache] | None
         self._oid_dumpers = None
 
         # mapping fmt, oid -> Loader instance
-        self._loaders: Tuple[LoaderCache, LoaderCache] = ({}, {})
+        self._loaders: tuple[LoaderCache, LoaderCache] = ({}, {})
 
         self._row_dumpers: list[abc.Dumper] | None = None
 
@@ -333,7 +333,7 @@ class Transformer(AdaptContext):
 
         return make_row(record)
 
-    def load_sequence(self, record: Sequence[Buffer | None]) -> Tuple[Any, ...]:
+    def load_sequence(self, record: Sequence[Buffer | None]) -> tuple[Any, ...]:
         if len(self._row_loaders) != len(record):
             raise e.ProgrammingError(
                 f"cannot load sequence of {len(record)} items:"
index 5cbdf00a7d54d735f097908457f1d19b75d2f85e..517ed7af9bbefb1b6c6e594d6a8ec9faf35ebe09 100644 (file)
@@ -8,7 +8,7 @@ from __future__ import annotations
 
 import re
 from typing import Any, Callable, Mapping, Match, NamedTuple
-from typing import Sequence, Tuple, TYPE_CHECKING
+from typing import Sequence, TYPE_CHECKING
 from functools import lru_cache
 
 from . import pq
@@ -47,7 +47,7 @@ class PostgresQuery:
 
         self.params: Sequence[Buffer | None] | None = None
         # these are tuples so they can be used as keys e.g. in prepared stmts
-        self.types: Tuple[int, ...] = ()
+        self.types: tuple[int, ...] = ()
 
         # The format requested by the user and the ones to really pass Postgres
         self._want_formats: list[PyFormat] | None = None
@@ -169,13 +169,13 @@ class PostgresQuery:
 
 # The type of the _query2pg() and _query2pg_nocache() methods
 _Query2Pg: TypeAlias = Callable[
-    [bytes, str], Tuple[bytes, list[PyFormat], list[str] | None, list[QueryPart]]
+    [bytes, str], tuple[bytes, list[PyFormat], list[str] | None, list[QueryPart]]
 ]
 
 
 def _query2pg_nocache(
     query: bytes, encoding: str
-) -> Tuple[bytes, list[PyFormat], list[str] | None, list[QueryPart]]:
+) -> tuple[bytes, list[PyFormat], list[str] | None, list[QueryPart]]:
     """
     Convert Python query and params into something Postgres understands.
 
@@ -199,7 +199,7 @@ def _query2pg_nocache(
             formats.append(part.format)
 
     elif isinstance(parts[0].item, str):
-        seen: dict[str, Tuple[bytes, PyFormat]] = {}
+        seen: dict[str, tuple[bytes, PyFormat]] = {}
         order = []
         for part in parts[:-1]:
             assert isinstance(part.item, str)
@@ -285,13 +285,13 @@ class PostgresClientQuery(PostgresQuery):
 
 
 _Query2PgClient: TypeAlias = Callable[
-    [bytes, str], Tuple[bytes, list[str] | None, list[QueryPart]]
+    [bytes, str], tuple[bytes, list[str] | None, list[QueryPart]]
 ]
 
 
 def _query2pg_client_nocache(
     query: bytes, encoding: str
-) -> Tuple[bytes, list[str] | None, list[QueryPart]]:
+) -> tuple[bytes, list[str] | None, list[QueryPart]]:
     """
     Convert Python query and params into a template to perform client-side binding
     """
@@ -306,7 +306,7 @@ def _query2pg_client_nocache(
             chunks.append(b"%s")
 
     elif isinstance(parts[0].item, str):
-        seen: dict[str, Tuple[bytes, PyFormat]] = {}
+        seen: dict[str, tuple[bytes, PyFormat]] = {}
         order = []
         for part in parts[:-1]:
             assert isinstance(part.item, str)
@@ -347,7 +347,7 @@ _re_placeholder = re.compile(
 def _split_query(
     query: bytes, encoding: str = "ascii", collapse_double_percent: bool = True
 ) -> list[QueryPart]:
-    parts: list[Tuple[bytes, Match[bytes] | None]] = []
+    parts: list[tuple[bytes, Match[bytes] | None]] = []
     cur = 0
 
     # pairs [(fragment, match], with the last match None
index 6d8da5a128d369f7a0677388eebe254423f92d36..a09f8b53590ee9e1f625633d7f7fbcc0cc4b4643 100644 (file)
@@ -7,20 +7,20 @@ Utility functions to deal with binary structs.
 from __future__ import annotations
 
 import struct
-from typing import Callable, cast, Protocol, Tuple
+from typing import Callable, cast, Protocol
 
 from . import errors as e
 from .abc import Buffer
 from ._compat import TypeAlias
 
 PackInt: TypeAlias = Callable[[int], bytes]
-UnpackInt: TypeAlias = Callable[[Buffer], Tuple[int]]
+UnpackInt: TypeAlias = Callable[[Buffer], tuple[int]]
 PackFloat: TypeAlias = Callable[[float], bytes]
-UnpackFloat: TypeAlias = Callable[[Buffer], Tuple[float]]
+UnpackFloat: TypeAlias = Callable[[Buffer], tuple[float]]
 
 
 class UnpackLen(Protocol):
-    def __call__(self, data: Buffer, start: int | None) -> Tuple[int]: ...
+    def __call__(self, data: Buffer, start: int | None) -> tuple[int]: ...
 
 
 pack_int2 = cast(PackInt, struct.Struct("!h").pack)
index 90202f8917381a08cc563f6dbc9acf8bb6a8986e..6eef150813da1bcb14817f88b6988770a8a36c47 100644 (file)
@@ -7,7 +7,7 @@ Protocol objects representing different implementations of the same classes.
 from __future__ import annotations
 
 from typing import Any, Callable, Generator, Mapping
-from typing import Protocol, Sequence, Tuple, TYPE_CHECKING
+from typing import Protocol, Sequence, TYPE_CHECKING
 
 from . import pq
 from ._enums import PyFormat as PyFormat
@@ -30,7 +30,7 @@ Query: TypeAlias = LiteralString | bytes | "sql.SQL" | "sql.Composed"
 Params: TypeAlias = Sequence[Any] | Mapping[str, Any]
 ConnectionType = TypeVar("ConnectionType", bound="BaseConnection[Any]")
 PipelineCommand: TypeAlias = Callable[[], None]
-DumperKey: TypeAlias = type | Tuple["DumperKey", ...]
+DumperKey: TypeAlias = type | tuple["DumperKey", ...]
 ConnParam: TypeAlias = str | int | None
 ConnDict: TypeAlias = dict[str, ConnParam]
 ConnMapping: TypeAlias = Mapping[str, ConnParam]
@@ -40,7 +40,7 @@ ConnMapping: TypeAlias = Mapping[str, ConnParam]
 
 RV = TypeVar("RV")
 
-PQGenConn: TypeAlias = Generator[Tuple[int, "Wait"], "Ready" | int, RV]
+PQGenConn: TypeAlias = Generator[tuple[int, Wait], Ready | int, RV]
 """Generator for processes where the connection file number can change.
 
 This can happen in connection and reset, but not in normal querying.
@@ -201,7 +201,7 @@ class Loader(Protocol):
 
 
 class Transformer(Protocol):
-    types: Tuple[int, ...] | None
+    types: tuple[int, ...] | None
     formats: list[pq.Format] | None
 
     def __init__(self, context: AdaptContext | None = None): ...
@@ -247,6 +247,6 @@ class Transformer(Protocol):
 
     def load_row(self, row: int, make_row: "RowMaker[Row]") -> "Row" | None: ...
 
-    def load_sequence(self, record: Sequence[Buffer | None]) -> Tuple[Any, ...]: ...
+    def load_sequence(self, record: Sequence[Buffer | None]) -> tuple[Any, ...]: ...
 
     def get_loader(self, oid: int, format: pq.Format) -> Loader: ...
index 48630758b59a80fe46654e226b18deb9a43bd85b..5a64e5fe77b26ef88ef23b7edc125c7d81e1d9a0 100644 (file)
@@ -6,7 +6,7 @@ psycopg client-side binding cursors
 
 from __future__ import annotations
 
-from typing import Tuple, TYPE_CHECKING
+from typing import TYPE_CHECKING
 from functools import partial
 
 from ._queries import PostgresQuery, PostgresClientQuery
@@ -79,7 +79,7 @@ class ClientCursorMixin(BaseCursor[ConnectionType, Row]):
 
     def _get_prepared(
         self, pgq: PostgresQuery, prepare: bool | None = None
-    ) -> Tuple[Prepare, bytes]:
+    ) -> tuple[Prepare, bytes]:
         return (Prepare.NO, b"")
 
 
index e0a82dfdae720b93838e9246a8c9995891c1a8a9..5d6472bba7e4095a6dfb9e5dae32fc569b257355 100644 (file)
@@ -21,7 +21,7 @@ DBAPI-defined Exceptions are defined in the following hierarchy::
 from __future__ import annotations
 
 from dataclasses import dataclass, field, fields
-from typing import Any, Callable, NoReturn, Sequence, Tuple, TYPE_CHECKING
+from typing import Any, Callable, NoReturn, Sequence, TYPE_CHECKING
 from asyncio import CancelledError
 
 from .pq.abc import PGconn, PGresult
@@ -298,7 +298,7 @@ class Error(Exception):
         """
         return Diagnostic(self._info, encoding=self._encoding)
 
-    def __reduce__(self) -> str | Tuple[Any, ...]:
+    def __reduce__(self) -> str | tuple[Any, ...]:
         res = super().__reduce__()
         if isinstance(res, tuple) and len(res) >= 3:
             # To make the exception picklable
@@ -513,7 +513,7 @@ class Diagnostic:
 
         return None
 
-    def __reduce__(self) -> str | Tuple[Any, ...]:
+    def __reduce__(self) -> str | tuple[Any, ...]:
         res = super().__reduce__()
         if isinstance(res, tuple) and len(res) >= 3:
             res[2]["_info"] = _info_to_dict(self._info)
index 27a6d1932edaa1b830d2739251c1662170e6c860..f157e1ce04890efc21590a6f8f96c53725c69280 100644 (file)
@@ -11,7 +11,7 @@ import ctypes
 import ctypes.util
 from ctypes import Structure, CFUNCTYPE, POINTER
 from ctypes import c_char, c_char_p, c_int, c_size_t, c_ubyte, c_uint, c_void_p
-from typing import Any, NoReturn, Tuple
+from typing import Any, NoReturn
 
 from .misc import find_libpq_full_path, version_pretty
 from ..errors import NotSupportedError
@@ -58,11 +58,11 @@ Oid = c_uint
 
 
 class PGconn_struct(Structure):
-    _fields_: list[Tuple[str, type]] = []
+    _fields_: list[tuple[str, type]] = []
 
 
 class PGresult_struct(Structure):
-    _fields_: list[Tuple[str, type]] = []
+    _fields_: list[tuple[str, type]] = []
 
 
 class PQconninfoOption_struct(Structure):
@@ -86,11 +86,11 @@ class PGnotify_struct(Structure):
 
 
 class PGcancelConn_struct(Structure):
-    _fields_: list[Tuple[str, type]] = []
+    _fields_: list[tuple[str, type]] = []
 
 
 class PGcancel_struct(Structure):
-    _fields_: list[Tuple[str, type]] = []
+    _fields_: list[tuple[str, type]] = []
 
 
 class PGresAttDesc_struct(Structure):
index 257c56a8f9254b38c99941a4456c17ec6b3c74e5..876a3f40879172fbc052682fc5beeb4e0cafceca 100644 (file)
@@ -6,7 +6,7 @@ Protocol objects to represent objects exposed by different pq implementations.
 
 from __future__ import annotations
 
-from typing import Any, Callable, Protocol, Sequence, Tuple, TYPE_CHECKING
+from typing import Any, Callable, Protocol, Sequence, TYPE_CHECKING
 
 from ._enums import Format, Trace
 from .._compat import TypeAlias
@@ -193,7 +193,7 @@ class PGconn(Protocol):
 
     def put_copy_end(self, error: bytes | None = None) -> int: ...
 
-    def get_copy_data(self, async_: int) -> Tuple[int, memoryview]: ...
+    def get_copy_data(self, async_: int) -> tuple[int, memoryview]: ...
 
     def trace(self, fileno: int) -> None: ...
 
index 7f184fbb863597b02d95787b5b6feb129e10ed15..a4b5c6828f29e4f53b172d7ee5bdf2d5f6e52905 100644 (file)
@@ -17,7 +17,7 @@ from weakref import ref
 
 from ctypes import Array, POINTER, cast, string_at, create_string_buffer, byref
 from ctypes import addressof, c_char_p, c_int, c_size_t, c_ulong, c_void_p, py_object
-from typing import Any, Callable, Sequence, Tuple
+from typing import Any, Callable, Sequence
 from typing import cast as t_cast, TYPE_CHECKING
 
 from .. import errors as e
@@ -644,7 +644,7 @@ class PGconn:
             raise e.OperationalError(f"sending copy end failed: {error_message(self)}")
         return rv
 
-    def get_copy_data(self, async_: int) -> Tuple[int, memoryview]:
+    def get_copy_data(self, async_: int) -> tuple[int, memoryview]:
         buffer_ptr = c_char_p()
         nbytes = impl.PQgetCopyData(self._pgconn_ptr, byref(buffer_ptr), async_)
         if nbytes == -2:
index bf5f5fe98373d897110b3151e3a02d0675e605fb..790e9c6243fa7f24829f88e4376c1c271ae16520 100644 (file)
@@ -8,7 +8,7 @@ from __future__ import annotations
 
 import functools
 from typing import Any, Callable, NamedTuple, NoReturn
-from typing import TYPE_CHECKING, Protocol, Sequence, Tuple
+from typing import TYPE_CHECKING, Protocol, Sequence
 from collections import namedtuple
 
 from . import pq
@@ -81,7 +81,7 @@ class BaseRowFactory(Protocol[Row]):
     def __call__(self, __cursor: "BaseCursor[Any, Any]") -> RowMaker[Row]: ...
 
 
-TupleRow: TypeAlias = Tuple[Any, ...]
+TupleRow: TypeAlias = tuple[Any, ...]
 """
 An alias for the type returned by `tuple_row()` (i.e. a tuple of any content).
 """
index feb1254b9af386bfabd2515548501a0a289ed1d1..7ff09d4f2851499333fe2e079a613cd3f71ec243 100644 (file)
@@ -9,7 +9,7 @@ from __future__ import annotations
 import re
 import struct
 from math import prod
-from typing import Any, cast, Callable, Pattern, Set, Tuple
+from typing import Any, cast, Callable, Pattern, Set
 
 from .. import pq
 from .. import errors as e
@@ -24,10 +24,10 @@ from .._typeinfo import TypeInfo
 
 _struct_head = struct.Struct("!III")  # ndims, hasnull, elem oid
 _pack_head = cast(Callable[[int, int, int], bytes], _struct_head.pack)
-_unpack_head = cast(Callable[[Buffer], Tuple[int, int, int]], _struct_head.unpack_from)
+_unpack_head = cast(Callable[[Buffer], tuple[int, int, int]], _struct_head.unpack_from)
 _struct_dim = struct.Struct("!II")  # dim, lower bound
 _pack_dim = cast(Callable[[int, int], bytes], _struct_dim.pack)
-_unpack_dim = cast(Callable[[Buffer, int], Tuple[int, int]], _struct_dim.unpack_from)
+_unpack_dim = cast(Callable[[Buffer, int], tuple[int, int]], _struct_dim.unpack_from)
 
 PY_TEXT = PyFormat.TEXT
 PQ_BINARY = pq.Format.BINARY
index 0f0fca0efeb8f62172c5be9b2ecd47ad47b1267c..91cb0e40097751e1642a2dab92468a525d1986ec 100644 (file)
@@ -10,7 +10,7 @@ import re
 import struct
 from collections import namedtuple
 from typing import Any, Callable, cast, Iterator
-from typing import NamedTuple, Sequence, Tuple, TYPE_CHECKING
+from typing import NamedTuple, Sequence, TYPE_CHECKING
 
 from .. import pq
 from .. import abc
@@ -29,7 +29,7 @@ if TYPE_CHECKING:
 _struct_oidlen = struct.Struct("!Ii")
 _pack_oidlen = cast(Callable[[int, int], bytes], _struct_oidlen.pack)
 _unpack_oidlen = cast(
-    Callable[[abc.Buffer, int], Tuple[int, int]], _struct_oidlen.unpack_from
+    Callable[[abc.Buffer, int], tuple[int, int]], _struct_oidlen.unpack_from
 )
 
 
@@ -121,7 +121,7 @@ class TupleDumper(SequenceDumper):
     # Should be this, but it doesn't work
     # oid = _oids.RECORD_OID
 
-    def dump(self, obj: Tuple[Any, ...]) -> Buffer | None:
+    def dump(self, obj: tuple[Any, ...]) -> Buffer | None:
         return self._dump_sequence(obj, b"(", b")", b",")
 
 
@@ -129,7 +129,7 @@ class TupleBinaryDumper(Dumper):
     format = pq.Format.BINARY
 
     # Subclasses must set this info
-    _field_types: Tuple[int, ...]
+    _field_types: tuple[int, ...]
 
     def __init__(self, cls: type, context: abc.AdaptContext | None = None):
         super().__init__(cls, context)
@@ -144,7 +144,7 @@ class TupleBinaryDumper(Dumper):
         nfields = len(self._field_types)
         self._formats = (PyFormat.from_pq(self.format),) * nfields
 
-    def dump(self, obj: Tuple[Any, ...]) -> Buffer | None:
+    def dump(self, obj: tuple[Any, ...]) -> Buffer | None:
         out = bytearray(pack_len(len(obj)))
         adapted = self._tx.dump_sequence(obj, self._formats)
         for i in range(len(obj)):
@@ -196,7 +196,7 @@ class BaseCompositeLoader(Loader):
 
 
 class RecordLoader(BaseCompositeLoader):
-    def load(self, data: abc.Buffer) -> Tuple[Any, ...]:
+    def load(self, data: abc.Buffer) -> tuple[Any, ...]:
         if data == b"()":
             return ()
 
@@ -217,9 +217,9 @@ class RecordBinaryLoader(Loader):
         # Usually there will be only one, but if there is more than one
         # row in the same query (in different columns, or even in different
         # records), oids might differ and we'd need separate transformers.
-        self._txs: dict[Tuple[int, ...], abc.Transformer] = {}
+        self._txs: dict[tuple[int, ...], abc.Transformer] = {}
 
-    def load(self, data: abc.Buffer) -> Tuple[Any, ...]:
+    def load(self, data: abc.Buffer) -> tuple[Any, ...]:
         nfields = unpack_len(data, 0)[0]
         offset = 4
         oids = []
@@ -346,13 +346,13 @@ def _nt_from_info(info: CompositeInfo) -> type[NamedTuple]:
 
 
 @cache
-def _make_nt(name: str, fields: Tuple[str, ...]) -> type[NamedTuple]:
+def _make_nt(name: str, fields: tuple[str, ...]) -> type[NamedTuple]:
     return namedtuple(name, fields)  # type: ignore[return-value]
 
 
 @cache
 def _make_loader(
-    name: str, types: Tuple[int, ...], factory: Callable[..., Any]
+    name: str, types: tuple[int, ...], factory: Callable[..., Any]
 ) -> type[BaseCompositeLoader]:
     return type(
         f"{name.title()}Loader",
@@ -377,7 +377,7 @@ def _make_dumper(name: str, oid: int) -> type[TupleDumper]:
 
 @cache
 def _make_binary_dumper(
-    name: str, oid: int, field_types: Tuple[int, ...]
+    name: str, oid: int, field_types: tuple[int, ...]
 ) -> type[TupleBinaryDumper]:
     return type(
         f"{name.title()}BinaryDumper",
index 55f8e92594d4bc19f08bd3c360e51187b174f4be..08bdf6d8164b9f91919f3415ce497313918ab79d 100644 (file)
@@ -9,7 +9,7 @@ from __future__ import annotations
 import re
 import struct
 from datetime import date, datetime, time, timedelta, timezone
-from typing import Any, Callable, cast, Tuple, TYPE_CHECKING
+from typing import Any, Callable, cast, TYPE_CHECKING
 
 from .. import _oids
 from ..pq import Format
@@ -24,12 +24,12 @@ if TYPE_CHECKING:
 
 _struct_timetz = struct.Struct("!qi")  # microseconds, sec tz offset
 _pack_timetz = cast(Callable[[int, int], bytes], _struct_timetz.pack)
-_unpack_timetz = cast(Callable[[Buffer], Tuple[int, int]], _struct_timetz.unpack)
+_unpack_timetz = cast(Callable[[Buffer], tuple[int, int]], _struct_timetz.unpack)
 
 _struct_interval = struct.Struct("!qii")  # microseconds, days, months
 _pack_interval = cast(Callable[[int, int, int], bytes], _struct_interval.pack)
 _unpack_interval = cast(
-    Callable[[Buffer], Tuple[int, int, int]], _struct_interval.unpack
+    Callable[[Buffer], tuple[int, int, int]], _struct_interval.unpack
 )
 
 utc = timezone.utc
index 1c4516e9bb9a630abc2c644b6361794c83a0b5e1..3f1f44ac91e668e1e6fa518e233a21f26cacc93b 100644 (file)
@@ -5,7 +5,7 @@ Adapters for the enum type.
 from __future__ import annotations
 
 from enum import Enum
-from typing import Any, Generic, Mapping, Sequence, Tuple, cast, TYPE_CHECKING
+from typing import Any, Generic, Mapping, Sequence, cast, TYPE_CHECKING
 
 from .. import sql
 from .. import postgres
@@ -24,11 +24,11 @@ E = TypeVar("E", bound=Enum)
 
 EnumDumpMap: TypeAlias = dict[E, bytes]
 EnumLoadMap: TypeAlias = dict[bytes, E]
-EnumMapping: TypeAlias = Mapping[E, str] | Sequence[Tuple[E, str]] | None
+EnumMapping: TypeAlias = Mapping[E, str] | Sequence[tuple[E, str]] | None
 
 # Hashable versions
-_HEnumDumpMap: TypeAlias = Tuple[Tuple[E, bytes], ...]
-_HEnumLoadMap: TypeAlias = Tuple[Tuple[bytes, E], ...]
+_HEnumDumpMap: TypeAlias = tuple[tuple[E, bytes], ...]
+_HEnumLoadMap: TypeAlias = tuple[tuple[bytes, E], ...]
 
 TEXT = Format.TEXT
 BINARY = Format.BINARY
@@ -170,7 +170,7 @@ def register_enum(
 
 
 @cache
-def _make_enum(name: str, labels: Tuple[str, ...]) -> Enum:
+def _make_enum(name: str, labels: tuple[str, ...]) -> Enum:
     return Enum(name.title(), labels, module=__name__)
 
 
index 18a2fd58fb2bfa675b523486107e6164632acdbd..47e85fff6ef1702288744aa27279dcfb6a25fbbc 100644 (file)
@@ -7,7 +7,7 @@ Adapters for JSON types.
 from __future__ import annotations
 
 import json
-from typing import Any, Callable, Tuple
+from typing import Any, Callable
 
 from .. import abc
 from .. import _oids
@@ -230,7 +230,7 @@ def _get_current_dumper(
         return _default_dumpers[cls, format]
 
 
-_default_dumpers: dict[Tuple[type[_JsonWrapper], PyFormat], type[Dumper]] = {
+_default_dumpers: dict[tuple[type[_JsonWrapper], PyFormat], type[Dumper]] = {
     (Json, PyFormat.BINARY): JsonBinaryDumper,
     (Json, PyFormat.TEXT): JsonDumper,
     (Jsonb, PyFormat.BINARY): JsonbBinaryDumper,
index 35c3a051b9c5e72025c691684b60ae5d4e0ea7a6..65bd109892c94e938a87405715ca4596797d8472 100644 (file)
@@ -10,7 +10,7 @@ import sys
 import struct
 from abc import ABC, abstractmethod
 from math import log
-from typing import Any, Callable, DefaultDict, Tuple, cast, TYPE_CHECKING
+from typing import Any, Callable, DefaultDict, cast, TYPE_CHECKING
 from decimal import Decimal, DefaultContext, Context
 
 from .. import _oids
@@ -315,7 +315,7 @@ for i in range(DefaultContext.prec):
     _contexts[i] = DefaultContext
 
 _unpack_numeric_head = cast(
-    Callable[[Buffer], Tuple[int, int, int, int]],
+    Callable[[Buffer], tuple[int, int, int, int]],
     struct.Struct("!HhHH").unpack_from,
 )
 _pack_numeric_head = cast(
@@ -370,7 +370,7 @@ class _MixedNumericDumper(Dumper, ABC):
     oid = _oids.NUMERIC_OID
 
     # If numpy is available, the dumped object might be a numpy integer too
-    int_classes: type | Tuple[type, ...] = ()
+    int_classes: type | tuple[type, ...] = ()
 
     def __init__(self, cls: type, context: AdaptContext | None = None):
         super().__init__(cls, context)
index 051112fa4c3749874e7a69f0ab9cb4da6213b31c..0fa3926fec5c0cfea92e21acf7c08fb33e0860b1 100644 (file)
@@ -7,7 +7,7 @@ Support for range types adaptation.
 from __future__ import annotations
 
 import re
-from typing import Any, Generic, Tuple, cast, TYPE_CHECKING
+from typing import Any, Generic, cast, TYPE_CHECKING
 from decimal import Decimal
 from datetime import date, datetime
 
@@ -470,7 +470,7 @@ class RangeLoader(BaseRangeLoader[T]):
         return load_range_text(data, self._load)[0]
 
 
-def load_range_text(data: Buffer, load: LoadFunc) -> Tuple[Range[Any], int]:
+def load_range_text(data: Buffer, load: LoadFunc) -> tuple[Range[Any], int]:
     if data == b"empty":
         return Range(empty=True), 5
 
index 1961b916131079343b812b8b3fc467722e331654..1c661ea99cd47a5ff890f484b005a4946d5482e7 100644 (file)
@@ -9,7 +9,7 @@ information. Will submit a bug.
 
 from __future__ import annotations
 
-from typing import Any, Sequence, Tuple
+from typing import Any, Sequence
 
 from psycopg import pq, abc, BaseConnection
 from psycopg.rows import Row, RowMaker
@@ -18,7 +18,7 @@ from psycopg.pq.abc import PGcancelConn, PGconn, PGresult
 from psycopg._compat import Deque
 
 class Transformer(abc.AdaptContext):
-    types: Tuple[int, ...] | None
+    types: tuple[int, ...] | None
     formats: list[pq.Format] | None
     def __init__(self, context: abc.AdaptContext | None = None): ...
     @classmethod
@@ -47,7 +47,7 @@ class Transformer(abc.AdaptContext):
     def get_dumper(self, obj: Any, format: PyFormat) -> abc.Dumper: ...
     def load_rows(self, row0: int, row1: int, make_row: RowMaker[Row]) -> list[Row]: ...
     def load_row(self, row: int, make_row: RowMaker[Row]) -> Row | None: ...
-    def load_sequence(self, record: Sequence[abc.Buffer | None]) -> Tuple[Any, ...]: ...
+    def load_sequence(self, record: Sequence[abc.Buffer | None]) -> tuple[Any, ...]: ...
     def get_loader(self, oid: int, format: pq.Format) -> abc.Loader: ...
 
 # Generators
@@ -73,8 +73,8 @@ def format_row_text(
 def format_row_binary(
     row: Sequence[Any], tx: abc.Transformer, out: bytearray | None = None
 ) -> bytearray: ...
-def parse_row_text(data: abc.Buffer, tx: abc.Transformer) -> Tuple[Any, ...]: ...
-def parse_row_binary(data: abc.Buffer, tx: abc.Transformer) -> Tuple[Any, ...]: ...
+def parse_row_text(data: abc.Buffer, tx: abc.Transformer) -> tuple[Any, ...]: ...
+def parse_row_binary(data: abc.Buffer, tx: abc.Transformer) -> tuple[Any, ...]: ...
 
 # Arrays optimization
 def array_load_text(
index 04af0856cffebbedaadf00a6ef18c6f5199eac37..dd34be1a9b3eb8cdf3625efd32748dba4a8b0694 100644 (file)
@@ -208,7 +208,7 @@ cdef int _append_text_none(bytearray out, Py_ssize_t *pos, int with_tab) except
     return 0
 
 
-def parse_row_binary(data, tx: Transformer) -> Tuple[Any, ...]:
+def parse_row_binary(data, tx: Transformer) -> tuple[Any, ...]:
     cdef unsigned char *ptr
     cdef Py_ssize_t bufsize
     _buffer_as_string_and_size(data, <char **>&ptr, &bufsize)
@@ -243,7 +243,7 @@ def parse_row_binary(data, tx: Transformer) -> Tuple[Any, ...]:
     return tx.load_sequence(row)
 
 
-def parse_row_text(data, tx: Transformer) -> Tuple[Any, ...]:
+def parse_row_text(data, tx: Transformer) -> tuple[Any, ...]:
     cdef unsigned char *fstart
     cdef Py_ssize_t size
     _buffer_as_string_and_size(data, <char **>&fstart, &size)
index 4e2ccdf0bc25aa4020da8cfb5b5ae9780a580dc0..b2f252f2cadab79028c9e8690c14d6d3517f0383 100644 (file)
@@ -19,7 +19,7 @@ from cpython.bytes cimport PyBytes_AS_STRING
 from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM
 from cpython.object cimport PyObject, PyObject_CallFunctionObjArgs
 
-from typing import Any, Iterable, Sequence, Tuple
+from typing import Any, Iterable, Sequence
 
 from psycopg import errors as e
 from psycopg.pq import Format as PqFormat
index b66804735cbdcd794d88e64e4cda30c42bca13f5..d0114852867136019599f30c38e8ee7dc1c7e6a4 100644 (file)
@@ -549,7 +549,7 @@ cdef class PGconn:
             raise e.OperationalError(f"sending copy end failed: {error_message(self)}")
         return rv
 
-    def get_copy_data(self, int async_) -> Tuple[int, memoryview]:
+    def get_copy_data(self, int async_) -> tuple[int, memoryview]:
         cdef char *buffer_ptr = NULL
         cdef int nbytes
         nbytes = libpq.PQgetCopyData(self._pgconn_ptr, &buffer_ptr, async_)
index 748d1362ae94beeebbb476975212a863cb39984c..2937698c13791a10008579181b2ade163370af04 100644 (file)
@@ -8,7 +8,7 @@ from __future__ import annotations
 
 from time import monotonic
 from random import random
-from typing import Any, Tuple, TYPE_CHECKING
+from typing import Any, TYPE_CHECKING
 
 from psycopg import errors as e
 
@@ -118,7 +118,7 @@ class BasePool:
         """`!True` if the pool is closed."""
         return self._closed
 
-    def _check_size(self, min_size: int, max_size: int | None) -> Tuple[int, int]:
+    def _check_size(self, min_size: int, max_size: int | None) -> tuple[int, int]:
         if max_size is None:
             max_size = min_size
 
index 9da58903fc6dd1f60e0f53c68a05a14bb3ac9310..e09a59f9b41414a95ebc985a8d42a0c0b23d5e18 100644 (file)
@@ -6,7 +6,7 @@ import ipaddress
 from math import isnan
 from uuid import UUID
 from random import choice, random, randrange
-from typing import Any, Set, Tuple
+from typing import Any, Set
 from decimal import Decimal
 from contextlib import contextmanager, asynccontextmanager
 
@@ -199,7 +199,7 @@ class Faker:
         )
 
     def choose_schema(self, ncols=20):
-        schema: list[Tuple[type, ...] | type] = []
+        schema: list[tuple[type, ...] | type] = []
         while len(schema) < ncols:
             s = self.make_schema(choice(self.types))
             if s is not None:
@@ -245,7 +245,7 @@ class Faker:
 
         return rv
 
-    def make_schema(self, cls: type) -> Tuple[type, ...] | type | None:
+    def make_schema(self, cls: type) -> tuple[type, ...] | type | None:
         """Create a schema spec from a Python type.
 
         A schema specifies what Postgres type to generate when a Python type
index ead6c6b21b1021014fa5ad8e155bf4828659b5df..6538e232d8ec28097f8ba7825f03790fc8a5c600 100644 (file)
@@ -1,6 +1,7 @@
+from __future__ import annotations
+
 import gc
 import sys
-from typing import Tuple
 
 import pytest
 
@@ -18,7 +19,7 @@ def pytest_configure(config):
     )
 
 
-NO_COUNT_TYPES: Tuple[type, ...] = ()
+NO_COUNT_TYPES: tuple[type, ...] = ()
 
 if sys.version_info[:2] == (3, 10):
     # On my laptop there are occasional creations of a single one of these objects
index b22ea435ef26a9b41a7f789feb66e70bfe85badf..4a967574907317f1e0e8e26a9969cd7eee94df21 100644 (file)
@@ -6,7 +6,7 @@ from __future__ import annotations
 import logging
 import weakref
 from time import time
-from typing import Any, Tuple
+from typing import Any
 
 import pytest
 
@@ -435,7 +435,7 @@ def test_grow(dsn, monkeypatch, min_size, want_times):
 
     with pool.ConnectionPool(dsn, min_size=min_size, max_size=4, num_workers=3) as p:
         p.wait(1.0)
-        results: list[Tuple[int, float]] = []
+        results: list[tuple[int, float]] = []
         ts = [spawn(worker, args=(i,)) for i in range(len(want_times))]
         gather(*ts)
 
@@ -449,7 +449,7 @@ def test_grow(dsn, monkeypatch, min_size, want_times):
 def test_shrink(dsn, monkeypatch):
     from psycopg_pool.pool import ShrinkPool
 
-    results: list[Tuple[int, int]] = []
+    results: list[tuple[int, int]] = []
 
     def run_hacked(self, pool):
         n0 = pool._nconns
index b18c3e42672e771b917f52b15f7152fc4fad3d92..8f522a6f4c7bd26bfaa84bcb4d7d209cf5a52fcb 100644 (file)
@@ -3,7 +3,7 @@ from __future__ import annotations
 import logging
 import weakref
 from time import time
-from typing import Any, Tuple
+from typing import Any
 
 import pytest
 
@@ -438,7 +438,7 @@ async def test_grow(dsn, monkeypatch, min_size, want_times):
         dsn, min_size=min_size, max_size=4, num_workers=3
     ) as p:
         await p.wait(1.0)
-        results: list[Tuple[int, float]] = []
+        results: list[tuple[int, float]] = []
         ts = [spawn(worker, args=(i,)) for i in range(len(want_times))]
         await gather(*ts)
 
@@ -452,7 +452,7 @@ async def test_grow(dsn, monkeypatch, min_size, want_times):
 async def test_shrink(dsn, monkeypatch):
     from psycopg_pool.pool_async import ShrinkPool
 
-    results: list[Tuple[int, int]] = []
+    results: list[tuple[int, int]] = []
 
     async def run_hacked(self, pool):
         n0 = pool._nconns
index fb994e024cd95267b1c98229d3bb02a0a69baa4f..60ef84b899aa20e892df144955a4a8d584ca0b20 100644 (file)
@@ -5,7 +5,7 @@ from __future__ import annotations
 
 import logging
 from time import time
-from typing import Any, Tuple
+from typing import Any
 
 import pytest
 
@@ -171,7 +171,7 @@ def test_queue(pool_cls, dsn):
         t1 = time()
         results.append((n, t1 - t0, pid))
 
-    results: list[Tuple[int, float, int]] = []
+    results: list[tuple[int, float, int]] = []
     with pool_cls(dsn, min_size=min_size(pool_cls, 2), max_size=2) as p:
         p.wait()
         ts = [spawn(worker, args=(i,)) for i in range(6)]
@@ -237,8 +237,8 @@ def test_queue_timeout(pool_cls, dsn):
             t1 = time()
             results.append((n, t1 - t0, pid))
 
-    results: list[Tuple[int, float, int]] = []
-    errors: list[Tuple[int, float, Exception]] = []
+    results: list[tuple[int, float, int]] = []
+    errors: list[tuple[int, float, Exception]] = []
 
     with pool_cls(dsn, min_size=min_size(pool_cls, 2), max_size=2, timeout=0.1) as p:
         ts = [spawn(worker, args=(i,)) for i in range(4)]
@@ -296,8 +296,8 @@ def test_queue_timeout_override(pool_cls, dsn):
             t1 = time()
             results.append((n, t1 - t0, pid))
 
-    results: list[Tuple[int, float, int]] = []
-    errors: list[Tuple[int, float, Exception]] = []
+    results: list[tuple[int, float, int]] = []
+    errors: list[tuple[int, float, Exception]] = []
 
     with pool_cls(dsn, min_size=min_size(pool_cls, 2), max_size=2, timeout=0.1) as p:
         ts = [spawn(worker, args=(i,)) for i in range(4)]
index 141e3e6d728ab30bccb467284b17ab9d09db34fb..01cc957a900a25b396b019dde087a09b4988161c 100644 (file)
@@ -2,7 +2,7 @@ from __future__ import annotations
 
 import logging
 from time import time
-from typing import Any, Tuple
+from typing import Any
 
 import pytest
 
@@ -181,7 +181,7 @@ async def test_queue(pool_cls, dsn):
         t1 = time()
         results.append((n, t1 - t0, pid))
 
-    results: list[Tuple[int, float, int]] = []
+    results: list[tuple[int, float, int]] = []
     async with pool_cls(dsn, min_size=min_size(pool_cls, 2), max_size=2) as p:
         await p.wait()
         ts = [spawn(worker, args=(i,)) for i in range(6)]
@@ -247,8 +247,8 @@ async def test_queue_timeout(pool_cls, dsn):
             t1 = time()
             results.append((n, t1 - t0, pid))
 
-    results: list[Tuple[int, float, int]] = []
-    errors: list[Tuple[int, float, Exception]] = []
+    results: list[tuple[int, float, int]] = []
+    errors: list[tuple[int, float, Exception]] = []
 
     async with pool_cls(
         dsn, min_size=min_size(pool_cls, 2), max_size=2, timeout=0.1
@@ -306,8 +306,8 @@ async def test_queue_timeout_override(pool_cls, dsn):
             t1 = time()
             results.append((n, t1 - t0, pid))
 
-    results: list[Tuple[int, float, int]] = []
-    errors: list[Tuple[int, float, Exception]] = []
+    results: list[tuple[int, float, int]] = []
+    errors: list[tuple[int, float, Exception]] = []
 
     async with pool_cls(
         dsn, min_size=min_size(pool_cls, 2), max_size=2, timeout=0.1
index ff05f0b01f48b2968258759f975c1f03d13f5928..1d44e4070606ff5762f6f9ea0a9261ecafaa9b92 100644 (file)
@@ -15,7 +15,7 @@ import asyncio
 import logging
 from contextlib import contextmanager
 from functools import partial
-from typing import Any, Iterator, Sequence, Tuple
+from typing import Any, Iterator, Sequence
 
 from psycopg import AsyncConnection, Connection
 from psycopg import pq, waiting
@@ -111,7 +111,7 @@ class LoggingPGconn:
 @contextmanager
 def prepare_pipeline_demo_pq(
     pgconn: LoggingPGconn, rows_to_send: int, logger: logging.Logger
-) -> Iterator[Tuple[Deque[PipelineCommand], Deque[str]]]:
+) -> Iterator[tuple[Deque[PipelineCommand], Deque[str]]]:
     """Set up pipeline demo with initial queries and yield commands and
     results queue for pipeline_communicate().
     """
index 4bea2c14d4cf46fe8c477da5d3c8ee3a66febc7d..12b51553ff7b861d3e4a390a07d24ff60f87ee72 100644 (file)
@@ -3,7 +3,7 @@
 from __future__ import annotations
 
 from dataclasses import dataclass
-from typing import Any, Callable, Sequence, Tuple
+from typing import Any, Callable, Sequence
 
 from psycopg import Connection, Cursor, ServerCursor, connect, rows
 from psycopg import AsyncConnection, AsyncCursor, AsyncServerCursor
@@ -113,8 +113,8 @@ def check_row_factory_connection() -> None:
     with conn2.cursor() as cur2:
         cur2.execute("select 2")
 
-    cur3: Cursor[Tuple[Any, ...]]
-    r3: Tuple[Any, ...] | None
+    cur3: Cursor[tuple[Any, ...]]
+    r3: tuple[Any, ...] | None
     conn3 = connect()
     cur3 = conn3.execute("select 3")
     with conn3.cursor() as cur3:
@@ -147,8 +147,8 @@ async def async_check_row_factory_connection() -> None:
     async with conn2.cursor() as cur2:
         await cur2.execute("select 2")
 
-    cur3: AsyncCursor[Tuple[Any, ...]]
-    r3: Tuple[Any, ...] | None
+    cur3: AsyncCursor[tuple[Any, ...]]
+    r3: tuple[Any, ...] | None
     conn3 = await AsyncConnection.connect()
     cur3 = await conn3.execute("select 3")
     async with conn3.cursor() as cur3:
@@ -159,7 +159,7 @@ async def async_check_row_factory_connection() -> None:
 
 def check_row_factories() -> None:
     conn1 = connect(row_factory=rows.tuple_row)
-    v1: Tuple[Any, ...] = conn1.execute("").fetchall()[0]
+    v1: tuple[Any, ...] = conn1.execute("").fetchall()[0]
 
     conn2 = connect(row_factory=rows.dict_row)
     v2: dict[str, Any] = conn2.execute("").fetchall()[0]
index c2a97307aa6b3ec59e39c82e89dddb875bc5c955..443fba1c79b64f9240fecc0d4e5718a803cf2f9d 100644 (file)
@@ -3,7 +3,7 @@ from __future__ import annotations
 import re
 import sys
 import operator
-from typing import Callable, Tuple
+from typing import Callable
 from contextlib import contextmanager
 
 
@@ -73,7 +73,7 @@ class VersionCheck:
         *,
         skip: bool = False,
         op: str | None = None,
-        version_tuple: Tuple[int, ...] = (),
+        version_tuple: tuple[int, ...] = (),
         whose: str = "(wanted)",
         postgres_rule: bool = False,
     ):
@@ -136,7 +136,7 @@ class VersionCheck:
 
     _OP_NAMES = {">=": "ge", "<=": "le", ">": "gt", "<": "lt", "==": "eq", "!=": "ne"}
 
-    def _match_version(self, got_tuple: Tuple[int, ...]) -> bool:
+    def _match_version(self, got_tuple: tuple[int, ...]) -> bool:
         if not self.version_tuple:
             return True
 
@@ -145,11 +145,11 @@ class VersionCheck:
             assert len(version_tuple) <= 2
             version_tuple = version_tuple[:1] + (0,) + version_tuple[1:]
 
-        op: Callable[[Tuple[int, ...], Tuple[int, ...]], bool]
+        op: Callable[[tuple[int, ...], tuple[int, ...]], bool]
         op = getattr(operator, self._OP_NAMES[self.op])
         return op(got_tuple, version_tuple)
 
-    def _parse_int_version(self, version: int | None) -> Tuple[int, ...]:
+    def _parse_int_version(self, version: int | None) -> tuple[int, ...]:
         if version is None:
             return ()
         version, ver_fix = divmod(version, 100)