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

INTERNAL ERROR triggered by broken typing

Open aberres opened this issue 3 years ago • 1 comments

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.

  • Python: 3.10
  • SQLAlchemy: 1.4.39
  • mypy: 0.961
  • SQLAlchemy2-stubs: 0.0.2a24

aberres avatar Jul 11 '22 10:07 aberres

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)

CaselIT avatar Jul 11 '22 20:07 CaselIT