Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when temporary base class is resolved from mypy cache #218

Open
aberres opened this issue Jul 11, 2022 · 2 comments
Open

Crash when temporary base class is resolved from mypy cache #218

aberres opened this issue Jul 11, 2022 · 2 comments
Labels
bug Something isn't working mypy plugin something that has to do with the sqlalchemy mypy plugin

Comments

@aberres
Copy link

aberres commented Jul 11, 2022

Describe the bug
Given the code below I regularly run into a mypy crash when the cache is warm.

Expected behavior
No crash

To Reproduce
I am having a hard time to isolate the crash. It seems to be a combination of different (namespace?) packages and a change of the cache is needed. I tried to come up with a minimal example but failed.

Maybe it does ring a bell nevertheless... As the class is created in a function there is no module which can be looked up.

We ran into the issue when introducing a new test which creates a base class within the test function. Whenever we switched branches mypy crashed. The workaound is to move the instantiation out into the model.

from __future__ import annotations

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)
        name = Column(String)

Error

Traceback (most recent call last):
  File "/Users/armin/venv/weplan3.10/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/Users/armin/venv/weplan3.10/lib/python3.10/site-packages/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 96, in main
  File "mypy/main.py", line 173, in run_build
  File "mypy/build.py", line 154, in build
  File "mypy/build.py", line 230, in _build
  File "mypy/build.py", line 2729, in dispatch
  File "mypy/build.py", line 3080, in process_graph
  File "mypy/build.py", line 3158, in process_fresh_modules
  File "mypy/build.py", line 1991, in fix_cross_refs
  File "mypy/fixup.py", line 26, in fixup_module
  File "mypy/fixup.py", line 91, in visit_symbol_table
  File "mypy/fixup.py", line 49, in visit_type_info
  File "mypy/types.py", line 1174, in accept
  File "mypy/fixup.py", line 156, in visit_instance
  File "mypy/fixup.py", line 282, in lookup_fully_qualified_typeinfo
  File "mypy/lookup.py", line 29, in lookup_fully_qualified
AssertionError: Cannot find module for Base

Versions.

  • Python: 3.10
  • SQLAlchemy: 1.4.39
  • mypy: 0.961
  • SQLAlchemy2-stubs: 0.0.2a24
@aberres aberres added the requires triage New issue that requires categorization label Jul 11, 2022
@aberres
Copy link
Author

aberres commented Jul 11, 2022

Might be related to #141

@CaselIT
Copy link
Member

CaselIT commented Jul 11, 2022

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 CaselIT added bug Something isn't working mypy plugin something that has to do with the sqlalchemy mypy plugin and removed requires triage New issue that requires categorization labels Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mypy plugin something that has to do with the sqlalchemy mypy plugin
Projects
None yet
Development

No branches or pull requests

2 participants