Skip to content

Incompatible types in assignment when base declaration is in a separate file #264

@ghost

Description

Scenario that works as expected:
test_db.py:

from sqlalchemy import String
from sqlalchemy import Column
from sqlalchemy.orm import declarative_base

Base = declarative_base()
class User(Base):
    __tablename__ = "user"
    name = Column(String)

    def __init__(self, *, name: str):
        self.name = name

Command:
pipenv run mypy --follow-imports=skip test_db.py
Result:
Everything passes, yay! 🎉

Failure scenario:
test_db.py:

from sqlalchemy import String
from sqlalchemy import Column
from base_file import Base

class User(Base):
    __tablename__ = "user"
    name = Column(String)

    def __init__(self, *, name: str):
        self.name = name

base_file.py:

Base = declarative_base()

Command plus output:

pipenv run mypy --follow-imports=skip test_db.py
test_db.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "Column[String]")  [assignment]

Versions.

  • OS: mac
  • Python: 3.10.13
  • SQLAlchemy: 1.4.49
  • mypy: 1.3
  • SQLAlchemy2-stubs:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmypy pluginsomething that has to do with the sqlalchemy mypy plugin

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions