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

Mypy fails with inner class

Open kasium opened this issue 3 years ago • 1 comments

Describe the bug If a ORM class is created inside a function, mypy fails. As soon as the class is outside of a function, it works fine

Expected behavior No error

To Reproduce

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

def inner() -> None:
    Base = declarative_base()

    class _DummyTable(Base):
        __tablename__ = "user"
        col1 = Column(Integer, primary_key=True)
    instance = _DummyTable(col1=1)

Error

x.py:13:16: error: Unexpected keyword argument "col1" for "_DummyTable"  [call-arg]
        instance = _DummyTable(col1=1)

Versions.

  • OS: Linux
  • Python: 3.7.1
  • SQLAlchemy: 1.4.22
  • mypy: 0.910
  • SQLAlchemy2-stubs: 0.0.2a6

kasium avatar Jul 29 '21 14:07 kasium

As far as I can see this is a limitation with the mypy plugin. I'm open to open/search for an issue on their side if it helps

kasium avatar Aug 10 '21 05:08 kasium