From: Denis Laxalde Date: Tue, 25 Mar 2025 08:51:30 +0000 (-0400) Subject: Add type annotations to postgresql.pg_catalog X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=864f79d7c421cfa01b6e01eb95b76ffe77ff44d1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add type annotations to postgresql.pg_catalog Related to #6810. Closes: #12462 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12462 Pull-request-sha: 5a131cc9a94a2c9efa0e888fe504ebc03d84c7f0 Change-Id: Ie4494d61f815edefef6a896499db4292fd94a22a --- diff --git a/lib/sqlalchemy/dialects/postgresql/pg_catalog.py b/lib/sqlalchemy/dialects/postgresql/pg_catalog.py index 78f390a211..4841056cf9 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg_catalog.py +++ b/lib/sqlalchemy/dialects/postgresql/pg_catalog.py @@ -4,7 +4,13 @@ # # This module is part of SQLAlchemy and is released under # the MIT License: https://www.opensource.org/licenses/mit-license.php -# mypy: ignore-errors + +from __future__ import annotations + +from typing import Any +from typing import Optional +from typing import Sequence +from typing import TYPE_CHECKING from .array import ARRAY from .types import OID @@ -23,31 +29,37 @@ from ...types import String from ...types import Text from ...types import TypeDecorator +if TYPE_CHECKING: + from ...engine.interfaces import Dialect + from ...sql.type_api import _ResultProcessorType + # types -class NAME(TypeDecorator): +class NAME(TypeDecorator[str]): impl = String(64, collation="C") cache_ok = True -class PG_NODE_TREE(TypeDecorator): +class PG_NODE_TREE(TypeDecorator[str]): impl = Text(collation="C") cache_ok = True -class INT2VECTOR(TypeDecorator): +class INT2VECTOR(TypeDecorator[Sequence[int]]): impl = ARRAY(SmallInteger) cache_ok = True -class OIDVECTOR(TypeDecorator): +class OIDVECTOR(TypeDecorator[Sequence[int]]): impl = ARRAY(OID) cache_ok = True class _SpaceVector: - def result_processor(self, dialect, coltype): - def process(value): + def result_processor( + self, dialect: Dialect, coltype: object + ) -> _ResultProcessorType[list[int]]: + def process(value: Any) -> Optional[list[int]]: if value is None: return value return [int(p) for p in value.split(" ")]