Skip to content

TypeDecorator.process_bind_param can return more than Optional[Text] #205

@huonw

Description

@huonw

Currently, the process_bind_param method on TypeDecorator[_T] has signature:

def process_bind_param(self, value: Optional[_T], dialect: Dialect) -> Optional[typing_Text]: ...

Unfortunately, it looks like this is incorrect: I believe it can return anything that the underlying impl can accept. For instance, in SQLAlchemy's tests there's type decorators that return ints:

class MyNewIntType(types.TypeDecorator):
    impl = Integer

    def process_bind_param(self, value, dialect):
        return value * 10

    def process_result_value(self, value, dialect):
        return value * 10

    def copy(self):
        return MyNewIntType()

The process_bind_param return value should probably be loosened to match the Optional[Any] of its inverse operation process_result_value.

def process_result_value(self, value: Optional[Any], dialect: Dialect) -> Optional[_T]: ...

(This probably applies to process_literal_param too.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions