dropbox / sqlalchemy-stubs

Mypy plugin and stubs for SQLAlchemy
Apache License 2.0
570 stars 101 forks source link

Unexpected keyword argument "<column_key>" for "<model>" w/ mypy > 0.770 #193

Closed olirice closed 3 years ago

olirice commented 3 years ago

With mypy > 0.770 ORM models __init__ parameters are not recognized

Here's a minimal reproducable

# example.py
from typing import TYPE_CHECKING

from sqlalchemy import BigInteger, Text, Column, MetaData
from sqlalchemy.ext.declarative import declarative_base

Meta = MetaData()
Base = declarative_base(metadata=Meta)

class Book(Base):

    __tablename__ = "book"

    id = Column(BigInteger, primary_key=True)
    title = Column(Text, nullable=False)

book = Book(title="some title")  # this is line 21

The output of mypy example.py is

# example.py:21: error: Unexpected keyword argument "title" for "Book"

I'm happy to take a swing at resolving (admittedly might not succeed) if someone could give me a nudge in the right direction.

Version Info:

OS: macOS Catalina 10.15.14 Python: 3.8.6 Mypy: 0.790 (same issue exists in 0.780, 0.781, and 0.782)

olirice commented 3 years ago

I’m still getting this error but just saw it on 0.770 which I’ve been using for months without issue.

Closing until I can confirm it’s not user error

olirice commented 3 years ago

Confirmed was my mistake. Sorry for the noise