]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
style: drop string type aliases
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 7 May 2025 01:59:05 +0000 (03:59 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 7 May 2025 18:18:44 +0000 (20:18 +0200)
19 files changed:
psycopg/psycopg/_acompat.py
psycopg/psycopg/_adapters_map.py
psycopg/psycopg/_preparing.py
psycopg/psycopg/_py_transformer.py
psycopg/psycopg/_struct.py
psycopg/psycopg/_typeinfo.py
psycopg/psycopg/abc.py
psycopg/psycopg/errors.py
psycopg/psycopg/types/enum.py
psycopg/psycopg/types/hstore.py
psycopg/psycopg/types/json.py
psycopg_pool/psycopg_pool/_acompat.py
psycopg_pool/psycopg_pool/abc.py
psycopg_pool/psycopg_pool/null_pool.py
psycopg_pool/psycopg_pool/null_pool_async.py
psycopg_pool/psycopg_pool/pool.py
psycopg_pool/psycopg_pool/pool_async.py
tests/crdb/test_copy.py
tests/crdb/test_copy_async.py

index 04a5c6f2de9c12d41feba2dae864ea90bb617901..3511e0e7bca02f2a221e1f1ce0469971f39982ee 100644 (file)
@@ -19,7 +19,7 @@ from collections.abc import Callable, Coroutine
 from ._compat import TypeVar
 
 Worker: TypeAlias = threading.Thread
-AWorker: TypeAlias = "asyncio.Task[None]"
+AWorker: TypeAlias = asyncio.Task[None]
 T = TypeVar("T")
 
 
index f3142c02abee7a484021ade8248360bd42d336de..6c72f31e63501eccc6577b3455e07052deb635f8 100644 (file)
@@ -279,7 +279,7 @@ class AdaptersMap:
         from psycopg import types
 
         if cls.__module__.startswith(types.__name__):
-            if new := cast("type[RV]", getattr(_psycopg, cls.__name__, None)):
+            if new := cast(type[RV], getattr(_psycopg, cls.__name__, None)):
                 self._optimised[cls] = new
                 return new
 
index 2be4a3c6696beac2c1dcda11dc5ac18f675643eb..7dbcd66c1e130d5c8b4e9de835d7e6461943d0b4 100644 (file)
@@ -19,7 +19,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
@@ -48,7 +48,7 @@ class PrepareManager:
         # Counter to generate prepared statements names
         self._prepared_idx = 0
 
-        self._to_flush = deque["bytes | None"]()
+        self._to_flush = deque[bytes | None]()
 
     @staticmethod
     def key(query: PostgresQuery) -> Key:
index 0f449b6207371c89e7f9b4dfa829a7698157aad0..ffba74e8c2e281f5f6063c4aace5dff8209280bc 100644 (file)
@@ -30,8 +30,8 @@ if TYPE_CHECKING:
     from ._connection_base import BaseConnection
 
 DumperCache: TypeAlias = "dict[DumperKey, abc.Dumper]"
-OidDumperCache: TypeAlias = "dict[int, abc.Dumper]"
-LoaderCache: TypeAlias = "dict[int, abc.Loader]"
+OidDumperCache: TypeAlias = dict[int, abc.Dumper]
+LoaderCache: TypeAlias = dict[int, abc.Loader]
 
 TEXT = pq.Format.TEXT
 PY_TEXT = PyFormat.TEXT
index 4926f5d4f19796fe5b8c7d39bfef2d60c39b7bbe..08e1e5ba1c5a0ca298d531d8e2555a64d454b0c1 100644 (file)
@@ -14,9 +14,9 @@ from . import errors as e
 from .abc import Buffer
 
 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):
index 1f897b33b712f3955c2d3a00ab13f1b587338109..5586dc026cebcf30f72d78e1eb6f0ca058473c9e 100644 (file)
@@ -26,7 +26,7 @@ if TYPE_CHECKING:
     from .connection_async import AsyncConnection
 
 T = TypeVar("T", bound="TypeInfo")
-RegistryKey: TypeAlias = "str | int | tuple[type, int]"
+RegistryKey: TypeAlias = str | int | tuple[type, int]
 
 
 class TypeInfo:
index fbab53ff1bf83cedce38c5499369b741c50449a1..a95c9e069f477c6873a19a4a68148897e40bbc5a 100644 (file)
@@ -14,10 +14,10 @@ from ._enums import PyFormat as PyFormat
 from ._compat import LiteralString, TypeVar
 
 if TYPE_CHECKING:
-    from . import sql  # noqa: F401
+    from . import sql
     from .rows import Row, RowMaker
     from .pq.abc import PGresult
-    from .waiting import Ready, Wait  # noqa: F401
+    from .waiting import Ready, Wait
     from ._adapters_map import AdaptersMap
     from ._connection_base import BaseConnection
 
@@ -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.
@@ -63,7 +63,7 @@ class WaitFunc(Protocol):
 
 # Adaptation types
 
-DumpFunc: TypeAlias = Callable[[Any], "Buffer | None"]
+DumpFunc: TypeAlias = Callable[[Any], Buffer | None]
 LoadFunc: TypeAlias = Callable[[Buffer], Any]
 
 
index be11e6c7caf5077fab8ba63ebfd2d6a63af9986f..2dfc76090e2e404cc8379e7dfea8061e72e014a5 100644 (file)
@@ -31,7 +31,7 @@ from .pq._enums import ConnStatus, DiagnosticField, PipelineStatus, TransactionS
 if TYPE_CHECKING:
     from .pq.misc import ConninfoOption, PGnotify
 
-ErrorInfo: TypeAlias = "PGresult | dict[int, bytes | None] | None"
+ErrorInfo: TypeAlias = PGresult | dict[int, bytes | None] | None
 
 _sqlcodes: dict[str, type[Error]] = {}
 
index fef2f1e406045d5a4a4fd312db4764ff07602b6b..9c718675aa3b277ae1595b0cbbfa5760f4be0627 100644 (file)
@@ -23,13 +23,13 @@ if TYPE_CHECKING:
 
 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"
+EnumDumpMap: TypeAlias = dict[E, bytes]
+EnumLoadMap: TypeAlias = dict[bytes, E]
+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
@@ -143,7 +143,7 @@ def register_enum(
         raise TypeError("no info passed. Is the requested enum available?")
 
     if enum is None:
-        enum = cast("type[E]", _make_enum(info.name, tuple(info.labels)))
+        enum = cast(type[E], _make_enum(info.name, tuple(info.labels)))
 
     info.enum = enum
     adapters = context.adapters if context else postgres.adapters
index cf91f6142623370029ae12dc9191c9adfa579803..49cd19a194e4aee9d60a6afd51570beb7ec86e82 100644 (file)
@@ -46,7 +46,7 @@ _I2B = [i.to_bytes(4, "big") for i in range(64)]
 """Lookup list for small ints to bytes conversions."""
 
 
-Hstore: TypeAlias = "dict[str, str | None]"
+Hstore: TypeAlias = dict[str, str | None]
 
 
 class BaseHstoreDumper(RecursiveDumper):
index d5b6149ccb198041010598603a36eb0d5f5a48f1..36ce929a72673024a8b397c7f29fba9700f039e4 100644 (file)
@@ -17,8 +17,8 @@ from ..pq import Format
 from ..adapt import AdaptersMap, Buffer, Dumper, Loader, PyFormat
 from ..errors import DataError
 
-JsonDumpsFunction: TypeAlias = Callable[[Any], "str | bytes"]
-JsonLoadsFunction: TypeAlias = Callable[["str | bytes"], Any]
+JsonDumpsFunction: TypeAlias = Callable[[Any], str | bytes]
+JsonLoadsFunction: TypeAlias = Callable[[str | bytes], Any]
 
 
 def set_json_dumps(
index 03ff960b82fe33a26ac75910be3dc0637be516b3..f5f3a022cb1d0adba482b3493669a24b25beb719 100644 (file)
@@ -31,7 +31,7 @@ ALock = asyncio.Lock
 sleep = time.sleep
 
 Worker: TypeAlias = threading.Thread
-AWorker: TypeAlias = "asyncio.Task[None]"
+AWorker: TypeAlias = asyncio.Task[None]
 
 
 def current_thread_name() -> str:
index 5a14c42be216bc4902e9095a627afb741ab9f723..16d6d745cbd5b8d46191b1df2e5620d73b8ff3a0 100644 (file)
@@ -12,7 +12,7 @@ from collections.abc import Awaitable, Callable
 from ._compat import TypeVar
 
 if TYPE_CHECKING:
-    from typing import Any  # noqa: F401
+    from typing import Any
 
     from psycopg import AsyncConnection, Connection  # noqa: F401
     from psycopg.rows import TupleRow  # noqa: F401
index 0370702ef62555bef397868443405087413d9c25..884eab850997cc1a615f598af2a1be77d73a98ab 100644 (file)
@@ -31,7 +31,7 @@ class NullConnectionPool(_BaseNullConnectionPool, ConnectionPool[CT]):
         self,
         conninfo: str = "",
         *,
-        connection_class: type[CT] = cast("type[CT]", Connection),
+        connection_class: type[CT] = cast(type[CT], Connection),
         kwargs: dict[str, Any] | None = None,
         min_size: int = 0,
         max_size: int | None = None,
index 53a2201c9c17ed337d13c7b5304bf2588888c93c..a037597fa045e2fecb89ef446b7a250570f279aa 100644 (file)
@@ -27,7 +27,7 @@ class AsyncNullConnectionPool(_BaseNullConnectionPool, AsyncConnectionPool[ACT])
         self,
         conninfo: str = "",
         *,
-        connection_class: type[ACT] = cast("type[ACT]", AsyncConnection),
+        connection_class: type[ACT] = cast(type[ACT], AsyncConnection),
         kwargs: dict[str, Any] | None = None,
         min_size: int = 0,  # Note: min_size default value changed to 0.
         max_size: int | None = None,
index 1c6e3882573320783b4060177020c303e43a3657..8626c6c0989600621abeb117305e7972a7f4d2e3 100644 (file)
@@ -42,7 +42,7 @@ class ConnectionPool(Generic[CT], BasePool):
         self,
         conninfo: str = "",
         *,
-        connection_class: type[CT] = cast("type[CT]", Connection),
+        connection_class: type[CT] = cast(type[CT], Connection),
         kwargs: dict[str, Any] | None = None,
         min_size: int = 4,
         max_size: int | None = None,
index ce7f070888fffb3a8d12dba82c9cc55ab366bc6c..796955f14960a4994444a82cc46512bdd819d937 100644 (file)
@@ -42,7 +42,7 @@ class AsyncConnectionPool(Generic[ACT], BasePool):
         self,
         conninfo: str = "",
         *,
-        connection_class: type[ACT] = cast("type[ACT]", AsyncConnection),
+        connection_class: type[ACT] = cast(type[ACT], AsyncConnection),
         kwargs: dict[str, Any] | None = None,
         min_size: int = 4,
         max_size: int | None = None,
index aa2d1024b048d8790cfc35a5a2efcd1fdbd2c650..f4967a7d4f3db077bd079507dfb7a48419f4a0b7 100644 (file)
@@ -124,7 +124,7 @@ def test_copy_in_records(conn, format):
     ensure_table(cur, sample_tabledef)
 
     with cur.copy(f"copy copy_in from stdin {copyopt(format)}") as copy:
-        row: "tuple[Any, ...]"
+        row: tuple[Any, ...]
         for row in sample_records:
             if format == pq.Format.BINARY:
                 row = tuple((Int4(i) if isinstance(i, int) else i for i in row))
index 60c52ab52f30a9dd731b5bf2a77a5f7bbca9cecf..ed4d604c9db4677bf5a1f8458e905a13617dbe7f 100644 (file)
@@ -123,7 +123,7 @@ async def test_copy_in_records(aconn, format):
     await ensure_table_async(cur, sample_tabledef)
 
     async with cur.copy(f"copy copy_in from stdin {copyopt(format)}") as copy:
-        row: "tuple[Any, ...]"
+        row: tuple[Any, ...]
         for row in sample_records:
             if format == pq.Format.BINARY:
                 row = tuple(Int4(i) if isinstance(i, int) else i for i in row)