]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add type annotations to postgresql.pg_catalog
authorDenis Laxalde <denis@laxalde.org>
Tue, 25 Mar 2025 08:51:30 +0000 (04:51 -0400)
committerFederico Caselli <cfederico87@gmail.com>
Tue, 1 Apr 2025 18:24:32 +0000 (20:24 +0200)
Related to #6810.

Closes: #12462
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12462
Pull-request-sha: 5a131cc9a94a2c9efa0e888fe504ebc03d84c7f0

Change-Id: Ie4494d61f815edefef6a896499db4292fd94a22a
(cherry picked from commit 864f79d7c421cfa01b6e01eb95b76ffe77ff44d1)

lib/sqlalchemy/dialects/postgresql/pg_catalog.py

index 78f390a2118a77e6805822fc8dddf9eb19ca111c..4841056cf9d1660a47c074906c6a71a7d5afecde 100644 (file)
@@ -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(" ")]