Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link

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:
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.