Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Column type] has no attribute "desc" #115

Closed
qsantos opened this issue Oct 3, 2019 · 2 comments
Closed

[Column type] has no attribute "desc" #115

qsantos opened this issue Oct 3, 2019 · 2 comments

Comments

@qsantos
Copy link

qsantos commented Oct 3, 2019

Let's say you have several models and want to write a method that can work on several of them using duck-typing. I wanted to provide proper typing by explicitly listing the models that could be passed to the method. However, this breaks the use of the model's fields as columns.

In the example below, the error is "int" has no attribute "desc". In other words, the field is interpreted as int instead of Column[int] that one would expect. Maybe there is a better way to type this method?

from typing import Type, Union

from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class MyModel(Base):
    created = Column(Integer, nullable=False)


def f(model: Type[Union[MyModel, MyModel]]) -> None:
    model.created.desc

Note: for a MWE, I have used Union[MyModel, MyModel] but it could just as well be two different models both defining the created column

Note: using Union[Model] does not trigger the error

@ilevkivskyi
Copy link
Contributor

I think this is actually a mypy bug, see python/mypy#5570

@qsantos
Copy link
Author

qsantos commented Oct 14, 2019

Thanks for taking the time of transferring the bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants