Skip to content

New mypy update producing errors from "typical" sqlalchemy usage #2971

Closed

Description

@Deimos

I'm not sure exactly what the cause of this is yet (still investigating), but I updated mypy and typed-ast today to the new versions and had a large number of errors start showing up. Here's an example of a really straightforward usage of SQLAlchemy (almost straight out of the ORM tutorial) that's now producing mypy errors:

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

Base = declarative_base()

class User(Base):
    __tablename__ = 'users'

    name = Column(String)

    def __init__(self, name: str) -> None:
        self.name = name

The error is:

error: Incompatible types in assignment (expression has type "Column", variable has type "str")

Activity

  1. gvanrossum commented on Mar 6, 2017

    @gvanrossum
    Member

    I don't know much about sqlalchemy myself, but two places to look: (a) the stubs in typeshed for sqlalchemy were improved; (b) it looks like Column should be a descriptor (i.e. have at least a __get__ method) but maybe that's not in the stubs? The descriptor's return type would indicate the field type in the instance.

  2. Deimos commented on Mar 7, 2017

    @Deimos
    ContributorAuthor

    Thanks for such a quick response. It definitely seems to be related to the updated stubs, just removing the sqlalchemy stubs entirely gets rid of all the new errors.

    I'm not familiar enough with how stubs work to know what might be the best approach for fixing this though. Do you think they should just be removed from typeshed in their current state, if they produce errors for normal sqlalchemy usage? Should I open an issue in the typeshed repo instead?

  3. gvanrossum commented on Mar 7, 2017

    @gvanrossum
    Member

    I don't think they should be removed (they are clearly useful for some people) but they should be fixed. Starting with an issue on typeshed sounds right -- call out the authors of the current stubs explicitly there.

  4. Deimos commented on Mar 7, 2017

    @Deimos
    ContributorAuthor

    Sounds good, thanks. I'll close this one and open a new issue over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions