]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: use TypeVar from typing_extension
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 3 Jan 2024 00:33:35 +0000 (01:33 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 3 Jan 2024 02:43:31 +0000 (03:43 +0100)
This includes the default parameter, which should fix the problem of the
awkward definition of Row defaulting to TupleRow.

16 files changed:
psycopg/psycopg/_acompat.py
psycopg/psycopg/_adapters_map.py
psycopg/psycopg/_compat.py
psycopg/psycopg/_connection_base.py
psycopg/psycopg/_typeinfo.py
psycopg/psycopg/abc.py
psycopg/psycopg/pq/_debug.py
psycopg/psycopg/rows.py
psycopg/psycopg/types/enum.py
psycopg/psycopg/types/range.py
psycopg/setup.cfg
psycopg_pool/psycopg_pool/_acompat.py
psycopg_pool/psycopg_pool/_compat.py
psycopg_pool/psycopg_pool/abc.py
psycopg_pool/setup.cfg
tests/constraints.txt

index 4915cab916fc54485224f92000e57a3734630480..cf106c5ba9d869fdafa6f304e348a5eb30ac0248 100644 (file)
@@ -13,10 +13,12 @@ from __future__ import annotations
 import queue
 import asyncio
 import threading
-from typing import Any, Callable, Coroutine, TypeVar, TYPE_CHECKING
+from typing import Any, Callable, Coroutine, TYPE_CHECKING
 
 from typing_extensions import TypeAlias
 
+from ._compat import TypeVar
+
 Worker: TypeAlias = threading.Thread
 AWorker: TypeAlias = "asyncio.Task[None]"
 T = TypeVar("T")
index fae5cb54521169f8ff729d4960e180e1a5d3eb1a..904ec71d18b83370df3ee4ea7395f7809bd0fbc2 100644 (file)
@@ -4,13 +4,14 @@ Mapping from types/oids to Dumpers/Loaders
 
 # Copyright (C) 2020 The Psycopg Team
 
-from typing import Any, Dict, List, Optional, Type, TypeVar, Union
+from typing import Any, Dict, List, Optional, Type, Union
 from typing import cast, TYPE_CHECKING
 
 from . import pq
 from . import errors as e
 from .abc import Dumper, Loader
 from ._enums import PyFormat as PyFormat
+from ._compat import TypeVar
 from ._cmodule import _psycopg
 from ._typeinfo import TypesRegistry
 
index c9e97e7609a00f5579520390c076c5e423d658e3..6ac16505de69b31d1a1ad1ea6ab142389650f333 100644 (file)
@@ -27,11 +27,17 @@ if sys.version_info >= (3, 11):
 else:
     from typing_extensions import LiteralString
 
+if sys.version_info >= (3, 13):
+    from typing import TypeVar
+else:
+    from typing_extensions import TypeVar
+
 __all__ = [
     "Counter",
     "Deque",
     "LiteralString",
     "TypeGuard",
+    "TypeVar",
     "ZoneInfo",
     "cache",
 ]
index fb8db5d91a2b8d4f3e78983e0bda165751394255..77b9b797ec05d40644817b13a305767f57035da9 100644 (file)
@@ -6,7 +6,7 @@ psycopg connection objects
 
 import logging
 from typing import Callable, Generic
-from typing import List, NamedTuple, Optional, Type, TypeVar, Tuple, Union
+from typing import List, NamedTuple, Optional, Type, Tuple, Union
 from typing import TYPE_CHECKING
 from weakref import ref, ReferenceType
 from warnings import warn
@@ -23,7 +23,7 @@ from ._tpc import Xid
 from .rows import Row
 from .adapt import AdaptersMap
 from ._enums import IsolationLevel
-from ._compat import LiteralString
+from ._compat import LiteralString, TypeVar
 from .pq.misc import connection_summary
 from .conninfo import ConnectionInfo
 from ._pipeline import BasePipeline
index 141ed04271682113890d3cf55c36f41f21b5d1aa..bfa740ff9f82602897ebbda04d345413b63a4386 100644 (file)
@@ -8,13 +8,14 @@ information to the adapters if needed.
 # Copyright (C) 2020 The Psycopg Team
 
 from typing import Any, Dict, Iterator, Optional, overload
-from typing import Sequence, Tuple, Type, TypeVar, Union, TYPE_CHECKING
+from typing import Sequence, Tuple, Type, Union, TYPE_CHECKING
 from typing_extensions import TypeAlias
 
 from . import sql
 from . import errors as e
 from .abc import AdaptContext, Query
 from .rows import dict_row
+from ._compat import TypeVar
 from ._encodings import conn_encoding
 
 if TYPE_CHECKING:
index 8edcdc10711b8e35d06e3227c23ac8319399df78..0952e8d0b5b4ba6e50e9d88f250c9dbc91ec138d 100644 (file)
@@ -5,13 +5,13 @@ Protocol objects representing different implementations of the same classes.
 # Copyright (C) 2020 The Psycopg Team
 
 from typing import Any, Callable, Generator, Mapping
-from typing import List, Optional, Protocol, Sequence, Tuple, TypeVar, Union
+from typing import List, Optional, Protocol, Sequence, Tuple, Union
 from typing import TYPE_CHECKING
 from typing_extensions import TypeAlias
 
 from . import pq
 from ._enums import PyFormat as PyFormat
-from ._compat import LiteralString
+from ._compat import LiteralString, TypeVar
 
 if TYPE_CHECKING:
     from . import sql
index f86f3bdcb1e00cdfcf86446d7d60131a388275b2..50fc819e4995e32567f02beaa898a459240cf6c3 100644 (file)
@@ -30,8 +30,9 @@ Suggested usage::
 
 import inspect
 import logging
-from typing import Any, Callable, Type, TypeVar, TYPE_CHECKING
+from typing import Any, Callable, Type, TYPE_CHECKING
 from functools import wraps
+from .._compat import TypeVar
 
 from . import PGconn
 from .misc import connection_summary
index f9b78e5e2850a8b312b05adcb314b5c31745245d..d0d834864face9bf06dde87bd297d8dc6143810c 100644 (file)
@@ -6,12 +6,13 @@ psycopg row factories
 
 import functools
 from typing import Any, Callable, Dict, List, Optional, NamedTuple, NoReturn
-from typing import TYPE_CHECKING, Protocol, Sequence, Tuple, Type, TypeVar
+from typing import TYPE_CHECKING, Protocol, Sequence, Tuple, Type
 from collections import namedtuple
 from typing_extensions import TypeAlias
 
 from . import pq
 from . import errors as e
+from ._compat import TypeVar
 from ._encodings import _as_python_identifier
 
 if TYPE_CHECKING:
index 3035214ba36c5899b9e1e18886b003254815beec..e15c1129951cb4dbef3380ac15ddd9681015d7c3 100644 (file)
@@ -3,7 +3,7 @@ Adapters for the enum type.
 """
 from enum import Enum
 from typing import Any, Dict, Generic, Optional, Mapping, Sequence
-from typing import Tuple, Type, TypeVar, Union, cast, TYPE_CHECKING
+from typing import Tuple, Type, Union, cast, TYPE_CHECKING
 from typing_extensions import TypeAlias
 
 from .. import sql
@@ -12,7 +12,7 @@ from .. import errors as e
 from ..pq import Format
 from ..abc import AdaptContext, Query
 from ..adapt import Buffer, Dumper, Loader
-from .._compat import cache
+from .._compat import cache, TypeVar
 from .._encodings import conn_encoding
 from .._typeinfo import TypeInfo
 
index 6290ca080d84efef81c020b0e0793d539a57aa64..9d91f89104c20da0aea0c7648b52332268edfc43 100644 (file)
@@ -5,7 +5,7 @@ Support for range types adaptation.
 # Copyright (C) 2020 The Psycopg Team
 
 import re
-from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Type, Tuple
+from typing import Any, Callable, Dict, Generic, List, Optional, Type, Tuple
 from typing import cast, TYPE_CHECKING
 from decimal import Decimal
 from datetime import date, datetime
@@ -18,7 +18,7 @@ from ..pq import Format
 from ..abc import AdaptContext, Buffer, Dumper, DumperKey, Query
 from ..adapt import RecursiveDumper, RecursiveLoader, PyFormat
 from .._oids import INVALID_OID, TEXT_OID
-from .._compat import cache
+from .._compat import cache, TypeVar
 from .._struct import pack_len, unpack_len
 from .._typeinfo import TypeInfo, TypesRegistry
 
index 900418f57308698b1f1e696c244f81f12bafc85a..f335c589655d0e107029339cafb67aab20053445 100644 (file)
@@ -53,7 +53,7 @@ packages = find:
 zip_safe = False
 install_requires =
     backports.zoneinfo >= 0.2.0; python_version < "3.9"
-    typing-extensions >= 4.2
+    typing-extensions >= 4.4
     tzdata; sys_platform == "win32"
 
 [options.extras_require]
@@ -65,7 +65,7 @@ pool =
     psycopg-pool
 test =
     anyio >= 4.0
-    mypy >= 1.4.1
+    mypy >= 1.6
     pproxy >= 2.7
     pytest >= 6.2.5
     pytest-cov >= 3.0
@@ -76,7 +76,7 @@ dev =
     black >= 23.1.0
     dnspython >= 2.1
     flake8 >= 4.0
-    mypy >= 1.4.1
+    mypy >= 1.6
     types-setuptools >= 57.4
     wheel >= 0.37
 docs =
index 09de06cc022cf75a5b2b797a8dfc2e05d68f5524..d6417590ba67e24402601ee7a8b3b97c1d1839b1 100644 (file)
@@ -14,10 +14,12 @@ import queue
 import asyncio
 import logging
 import threading
-from typing import Any, Callable, Coroutine, TypeVar, TYPE_CHECKING
+from typing import Any, Callable, Coroutine, TYPE_CHECKING
 
 from typing_extensions import TypeAlias
 
+from ._compat import TypeVar
+
 logger = logging.getLogger("psycopg.pool")
 T = TypeVar("T")
 
index e88cf2b3d15952a2a337b685dc99097a038df222..5917ff31b71e236e45153cf818f7650414e96af2 100644 (file)
@@ -19,10 +19,16 @@ if sys.version_info >= (3, 11):
 else:
     from typing_extensions import Self
 
+if sys.version_info >= (3, 13):
+    from typing import TypeVar
+else:
+    from typing_extensions import TypeVar
+
 __all__ = [
     "Counter",
     "Deque",
     "Self",
+    "TypeVar",
 ]
 
 # Workaround for psycopg < 3.0.8.
index 5cc72f7fedd218870752013ba1627f0ae91c553f..9d76b17fd84b81900638246eb2708ec61cd79547 100644 (file)
@@ -6,14 +6,16 @@ Types used in the psycopg_pool package
 
 from __future__ import annotations
 
-from typing import Any, Awaitable, Callable, TypeVar, Union, TYPE_CHECKING
+from typing import Any, Awaitable, Callable, Union, TYPE_CHECKING
 
 from typing_extensions import TypeAlias
 
+from ._compat import TypeVar
+
 if TYPE_CHECKING:
     from .pool import ConnectionPool
     from .pool_async import AsyncConnectionPool
-    from psycopg import Connection, AsyncConnection
+    from psycopg import Connection, AsyncConnection  # noqa: F401
 
 # Connection types to make the pool generic
 CT = TypeVar("CT", bound="Connection[Any]")
index 8c3de4ba124ef2a95a0aea9e737869bc9ac54a1a..0d4f476cb18e7ad5a5faa412867cb753c60c5951 100644 (file)
@@ -46,7 +46,7 @@ python_requires = >= 3.8
 packages = find:
 zip_safe = False
 install_requires =
-    typing-extensions >= 4.0
+    typing-extensions >= 4.4
 
 [options.package_data]
 psycopg_pool = py.typed
index 459f006e1bba31b94a836f2e9201d57d45b90530..a676a993f593fb40fe94032858a1799659834caa 100644 (file)
@@ -5,12 +5,12 @@
 
 # From install_requires
 backports.zoneinfo == 0.2.0
-typing-extensions == 4.2.0
+typing-extensions == 4.4.0
 importlib-metadata == 1.4
 
 # From the 'test' extra
 anyio == 4.0
-mypy == 1.4.1
+mypy == 1.6.0
 pproxy == 2.7.0
 pytest == 6.2.5
 pytest-cov == 3.0.0