dropbox / dropbox/sqlalchemy-stubs

TypeDecorator.process_bind_param can return more than Optional[Text]

Open
#205 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
583
Forks
96
PR merge metrics
No merged PRs in 30d

Description

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

https://github.com/dropbox/sqlalchemy-stubs/blob/8495c229cf8a31d75fcea36090e07c0e4b867605/sqlalchemy-stubs/sql/type_api.pyi#L95

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](https://github.com/sqlalchemy/sqlalchemy/blob/7bdb1f30f66aaea16efbcf96e314491058493e6c/test/sql/test_types.py#L542-L552) there's type decorators that return `int`s:

```python
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`.

https://github.com/dropbox/sqlalchemy-stubs/blob/8495c229cf8a31d75fcea36090e07c0e4b867605/sqlalchemy-stubs/sql/type_api.pyi#L96

(This probably applies to `process_literal_param` too.)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.