dropbox / dropbox/sqlalchemy-stubs

Adding attribute with index_property triggers mypy warning

Open
#137 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

Hi,

I'm getting a mypy error every time I want to create a model attribute from a JSON column. My mypy config uses the `sqlmypy` plugin. Without using this plugin, I don't get the error.

Here is a snippet that reproduces the issue:

```python
from sqlalchemy import Column, Integer, String
from sqlalchemy.dialects.sqlite import JSON
from sqlalchemy.ext.indexable import index_property
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Food(Base):

__tablename__ = "foods"
id = Column(Integer, primary_key=True)
name = Column(String)
properties = Column(JSON)

Food.taste = index_property("properties", "taste")
```

And here is the error:

```
demo/models.py:18:1: error: "Type[Food]" has no attribute "taste"
Found 1 error in 1 file (checked 1 source file)
```

Any idea how this needs to be handled? I can't add type hinting directly to the model for the `taste` attribute, since in my real-life use case the model doesn't know about what is contained in the `properties` column.

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.