sqlalchemy / sqlalchemy2-stubs

PEP-484 typing stubs for SQLAlchemy 1.4
MIT License
159 stars 41 forks source link

INTERNAL ERROR triggered by broken typing #219

Open aberres opened 2 years ago

aberres commented 2 years ago

Describe the bug Exception with INTERNAL ERROR: maximum semantic analysis iteration count reached

Expected behavior

A message like error: Name "Address" is not defined [name-defined]

To Reproduce Type check the code below.

Obviously, there is not class Address. When removing the base class, the error is emitted as expected. Stumbled upon this problem when having a typo in a relation.

from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

def test_soft():
    Base = declarative_base()

    class User(Base):
        __tablename__ = "user"

        id = Column(Integer, primary_key=True)
        addresses: list[Address]

Error

Deferral trace:
    [...]
    m2p.utils.tests.test_softdelete:12
    m2p.utils.tests.test_softdelete:12
    m2p.utils.tests.test_softdelete:12
    m2p.utils.tests.test_softdelete:12
    m2p.utils.tests.test_softdelete:12
    m2p.utils.tests.test_softdelete:12
    m2p.utils.tests.test_softdelete:12
test_softdelete.py: error: INTERNAL ERROR: maximum semantic analysis iteration count reached

Versions.

CaselIT commented 2 years ago

This is related to the mypy plugin. Since v2 will not use it it's unlikely that it will be fixed. PR are welcome though. (The plugin code lives in the main sqlalchemy repo)