From 3343901d142fef6589250f950483d61a83519ada Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Mon, 3 Mar 2025 12:37:12 +0100 Subject: [PATCH] Add type annotations to JSONElementType methods --- lib/sqlalchemy/sql/sqltypes.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index ec382c2f14..b141da188d 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -73,6 +73,7 @@ if TYPE_CHECKING: from .schema import MetaData from .type_api import _BindProcessorType from .type_api import _ComparatorFactory + from .type_api import _LiteralProcessorType from .type_api import _MatchedOnType from .type_api import _ResultProcessorType from ..engine.interfaces import Dialect @@ -2510,17 +2511,21 @@ class JSON(Indexable, TypeEngine[Any]): _integer = Integer() _string = String() - def string_bind_processor(self, dialect): + def string_bind_processor( + self, dialect: Dialect + ) -> Optional[_BindProcessorType[str]]: return self._string._cached_bind_processor(dialect) - def string_literal_processor(self, dialect): + def string_literal_processor( + self, dialect: Dialect + ) -> Optional[_LiteralProcessorType[str]]: return self._string._cached_literal_processor(dialect) - def bind_processor(self, dialect): + def bind_processor(self, dialect: Dialect) -> _BindProcessorType[Any]: int_processor = self._integer._cached_bind_processor(dialect) string_processor = self.string_bind_processor(dialect) - def process(value): + def process(value: Optional[Any]) -> Any: if int_processor and isinstance(value, int): value = int_processor(value) elif string_processor and isinstance(value, str): @@ -2529,11 +2534,13 @@ class JSON(Indexable, TypeEngine[Any]): return process - def literal_processor(self, dialect): + def literal_processor( + self, dialect: Dialect + ) -> _LiteralProcessorType[Any]: int_processor = self._integer._cached_literal_processor(dialect) string_processor = self.string_literal_processor(dialect) - def process(value): + def process(value: Optional[Any]) -> Any: if int_processor and isinstance(value, int): value = int_processor(value) elif string_processor and isinstance(value, str): -- 2.47.3