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

Implement plugins to detect declarative bases #6

Closed
ilevkivskyi opened this issue Aug 27, 2018 · 7 comments
Closed

Implement plugins to detect declarative bases #6

ilevkivskyi opened this issue Aug 27, 2018 · 7 comments

Comments

@ilevkivskyi
Copy link
Contributor

We currently can only detect declarative bases defined using @as_declarative, a plugin for detecting declarative_base() depends on python/mypy#5508

@ilevkivskyi
Copy link
Contributor Author

ilevkivskyi commented Aug 27, 2018

A potential problem here is how to store the fact that given TypeInfo is "special". We can of course just store something in TypeInfo.metadata, but other plugin hooks will only see the full name of this class. So maybe we need to keep some state in a plugin with all special class names. The question is then however how to recreate the state in incremental mode (when classes are loaded from cache).

@mehdigmira
Copy link
Contributor

Any news on this ?

Currently declarative_base() seems to be inferred as Any.

ilevkivskyi added a commit that referenced this issue Jan 16, 2019
Fixes #23
Helps with #5
Fixes #6
Helps with #8

I would propose to merge this soon, and then iterate on discovered issues. This branch is very old, it is time to move on with some minimal version.
@mehdigmira
Copy link
Contributor

This doesn't seem to be fixed by #49
I'm using mypy v0.660

from typing import Any

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


Base = declarative_base()
reveal_type(Base)  # revealed type is Any


class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String)


class Address(Base):
    __tablename__ = 'addresses'
    id = Column(Integer, primary_key=True)
    name = Column(String)


def f() -> Address:
    user = User(name="xx")
    return user  # mypy should log an error here but doesn't

@ilevkivskyi
Copy link
Contributor Author

It is. This is what I see

  main:8: error: Revealed type is 'def () -> main.Base'
  main:25: error: Incompatible return value type (got "User", expected "Address")

You need to enable the plugin in mypy config. Next time please make at least minimal effort before complaining.

@mehdigmira
Copy link
Contributor

mehdigmira commented Jan 17, 2019 via email

@JukkaL
Copy link
Contributor

JukkaL commented Jan 17, 2019

I wonder if the installation instructions in https://github.com/dropbox/sqlalchemy-stubs/blob/master/README.md are up-to-date with respect to the plugin?

@ilevkivskyi
Copy link
Contributor Author

@mehdigmira OK, I am sorry for being harsh, it's great that we found understanding.

@JukkaL Yes, I will update this before making the release.

kespindler pushed a commit to debtsy/sqlalchemy-stubs that referenced this issue Feb 2, 2019
Fixes dropbox#23
Helps with dropbox#5
Fixes dropbox#6
Helps with dropbox#8

I would propose to merge this soon, and then iterate on discovered issues. This branch is very old, it is time to move on with some minimal version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants