Skip to content

Commit

Permalink
Relax TypeDecorator.process_*_param to return Optional[Any]
Browse files Browse the repository at this point in the history
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 dropbox#205
  • Loading branch information
huonw committed Jan 25, 2021
1 parent 8495c22 commit 9dd367b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sqlalchemy-stubs/sql/type_api.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]]: ...
Expand Down

0 comments on commit 9dd367b

Please sign in to comment.