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

mypy crashes with "Cannot find component" on subsequent runs #18751

Open
johnfn opened this issue Mar 3, 2025 · 4 comments
Open

mypy crashes with "Cannot find component" on subsequent runs #18751

johnfn opened this issue Mar 3, 2025 · 4 comments

Comments

@johnfn
Copy link

johnfn commented Mar 3, 2025

Crash Report

Running mypy after the first run sometimes crashes.

rm -rf .mypy_cache fixes the issue, but if I then run mypy a few more times, it crashes again.

Traceback

$ mypy
Traceback (most recent call last):
File "/path/to/mypy/mypy", line 8, in <module> sys.exit(console_entry())
File "/path/to/mypy/_-main_-.py",line 15, in console_entry main(
File "mypy/main.py", line 119, in main
File "mypy/main.py"
File "mypy/build.py"
, line 203, in run_build , line 191, in build
File "mypy/build.py", line 267, in _build File "mypy/build.py", line 2937, in dispatch
File "mypy/build.py" , line 3328, in process-graph
File "mypy/build.py",
File '
"mypy/build.py"
line 3409, in process_fresh-modules , line 2107, in fix_cross_refs
File "mypy/fixup.py" , line 52, in fixup-module
File
"mypy/fixup.py" , line 128, in visit_symbol_table
File "mypy/lookup.py", line 49, in lookup_fully_qualified
AssertionError: Cannot find component 'operators' for 'sqlalchemy.sql.operators'

To Reproduce

This is at work, and it's a rather large repo, so I can't provide easy repro steps. I would be happy to provide additional information that you need.

Your Environment

  • Mypy version used: v1.15.0
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
mypy_path = server/python_stubs,server

files = server/,test/

explicit_package_bases = True
enable_incomplete_feature=InlineTypedDict

strict = True
warn_return_any = False
disallow_untyped_calls = False
no_implicit_reexport = False
warn_unreachable = True
plugins = pydantic.mypy

Additionally, we added ignore_missing_imports to most of our libraries.

  • Python version used:
  • python 3.11.11
  • Operating system and version:
  • macOS ventura
@johnfn johnfn added the crash label Mar 3, 2025
@johnfn
Copy link
Author

johnfn commented Mar 3, 2025

Here's another one I got just now.

Traceback (most recent call last):
  File "env//bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "env/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 119, in main
  File "mypy/main.py", line 203, in run_build
  File "mypy/build.py", line 191, in build
  File "mypy/build.py", line 267, in _build
  File "mypy/build.py", line 2937, in dispatch
  File "mypy/build.py", line 3328, in process_graph
  File "mypy/build.py", line 3409, in process_fresh_modules
  File "mypy/build.py", line 2107, in fix_cross_refs
  File "mypy/fixup.py", line 52, in fixup_module
  File "mypy/fixup.py", line 128, in visit_symbol_table
  File "mypy/lookup.py", line 49, in lookup_fully_qualified
AssertionError: Cannot find component 'attributes' for 'sqlalchemy.orm.attributes'

@johnfn johnfn mentioned this issue Mar 3, 2025
@colelin26
Copy link

Running into the same issue at work

@A5rocks A5rocks added the topic-daemon dmypy label Mar 6, 2025
@ilevkivskyi
Copy link
Member

Did the crash occur with previous version(s) of mypy? Did you recently update the version of sqlalchemy? (Just trying to understand where to start investigation, issues without repro are 10x harder to fix than issues with a repro).

@johnfn
Copy link
Author

johnfn commented Mar 10, 2025

I have managed to track this one down. We use sqlalchemy type stubs installed locally + sqlalchemy. It can happen sometimes if you import, say, sqlalchemy.sql.operators, which is defined in sqlalchemy, but the typestubs don't know about sqlalchemy.sql.operators and don't define it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants