From 9dd367b793dd308c4f5741ac985d7424ceb9e38d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 25 Jan 2021 16:25:15 +1100 Subject: [PATCH] Relax TypeDecorator.process_*_param to return Optional[Any] The process_bind_param and process_literal_param methods are called to do decorator-specific conversion of values, before deferring to the underlying .impl's conversion methods. This means they can return any value accepted by those methods, not just str (or typing.Text). These are related to the process_result_value method, which is effectively the inverse, doing decorator-specific conversion of the output of the underlying .impl, and indeed this method accepts value: Optional[Any], representing the unknown type of the output of the underlying .impl. Unfortunately, modelling this accurately is likely to be impossible (or at least, much more difficult), because, for instance, the `impl` property itself can only be typed as `Any`, let alone the input/output type it uses. Fixes #205 --- sqlalchemy-stubs/sql/type_api.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sqlalchemy-stubs/sql/type_api.pyi b/sqlalchemy-stubs/sql/type_api.pyi index 1675257..335ef6d 100644 --- a/sqlalchemy-stubs/sql/type_api.pyi +++ b/sqlalchemy-stubs/sql/type_api.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional, Union, TypeVar, Generic, Type, Callable, ClassVar, Tuple, Mapping, overload, Text as typing_Text +from typing import Any, Optional, Union, TypeVar, Generic, Type, Callable, ClassVar, Tuple, Mapping, overload from .. import util from .visitors import Visitable as Visitable, VisitableType as VisitableType from .base import SchemaEventTarget as SchemaEventTarget @@ -91,8 +91,8 @@ class TypeDecorator(SchemaEventTarget, TypeEngine[_T]): def type_engine(self, dialect: Dialect) -> TypeEngine[Any]: ... def load_dialect_impl(self, dialect: Dialect) -> TypeEngine[Any]: ... def __getattr__(self, key: str) -> Any: ... - def process_literal_param(self, value: Optional[_T], dialect: Dialect) -> Optional[str]: ... - def process_bind_param(self, value: Optional[_T], dialect: Dialect) -> Optional[typing_Text]: ... + def process_literal_param(self, value: Optional[_T], dialect: Dialect) -> Optional[Any]: ... + def process_bind_param(self, value: Optional[_T], dialect: Dialect) -> Optional[Any]: ... def process_result_value(self, value: Optional[Any], dialect: Dialect) -> Optional[_T]: ... def literal_processor(self, dialect: Dialect) -> Callable[[Optional[_T]], Optional[str]]: ... def bind_processor(self, dialect: Dialect) -> Callable[[Optional[_T]], Optional[str]]: ...