sqlalchemy2-stubs icon indicating copy to clipboard operation
sqlalchemy2-stubs copied to clipboard

Indirection when specifying column type leads to missing __init__ parameter

Open aberres opened this issue 3 years ago • 0 comments

Describe the bug

When a column type is not directly using an SA column class but instead an indirection is in place, the column is not added to __init__ and mypy complains about an invalid argument.

Maybe (or maybe not) related to https://github.com/sqlalchemy/sqlalchemy2-stubs/issues/141.

Expected behavior

No error.

To Reproduce

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

Base = declarative_base()

class DummyTable(Base):
    id = Column(String, primary_key=True)

# This causes the problem
# I stumbled upon this in my code with an ENUM(...) beeing used in multiple places
MyString = String

class DummyTable2(Base):
    id = Column(MyString, primary_key=True)


DummyTable(id="wer")
# error: Unexpected keyword argument "id" for "DummyTable2"  [call-arg]
DummyTable2(id="wer")

Error

foo.py:16: error: Unexpected keyword argument "id" for "DummyTable2"  [call-arg]
    DummyTable2(id="wer")
    ^
Found 1 error in 1 file (checked 1 source file)

Versions.

mypy==0.931 SQLAlchemy==1.4.31 sqlalchemy2-stubs==0.0.2a19

aberres avatar Feb 09 '22 13:02 aberres