python / python/mypy

AssertionError: Internal error: method must be called on parsed file only

Open
#14,521 18 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

crash topic-incremental
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

When I run mypy==0.991 in parallel, the following error randomly happens.

Traceback (most recent call last):
  File "/home/my_name/.pyenv/versions/3.9.16/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/my_name/.pyenv/versions/3.9.16/lib/python3.9/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 95, in main
  File "mypy/main.py", line 174, in run_build
  File "mypy/build.py", line 193, in build
  File "mypy/build.py", line 276, in _build
  File "mypy/build.py", line 2903, in dispatch
  File "mypy/build.py", line 3284, in process_graph
  File "mypy/build.py", line 3365, in process_fresh_modules
  File "mypy/build.py", line 2109, in fix_cross_refs
AssertionError: Internal error: method must be called on parsed file only

To Reproduce

I cannot identify to reproduce this problem because this error randomly happens (2-3% probabiliy), but I observed this problem only when I ran mypy in parallel on multiple files.

Your Environment

  • Mypy version used: mypy==0.991
  • Mypy command-line flags: mypy --follow-imports silent --config-file pyproject.toml path/to/foo.py
  • Mypy configuration options from mypy.ini (and other config files): pyproject.toml
[tool.mypy]
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "third_party.*"
ignore_errors = true
[[tool.mypy.overrides]]
module = "requests.*"
ignore_missing_imports = true
  • Python version used:3.9.16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in mypy/build.py at process_fresh_modules, fix_cross_refs, and the surrounding dispatch and process_graph calls shown in the traceback. Run the reported mypy==0.991 command concurrently on multiple files, focusing on the intermittent parallel failure. Done means the assertion no longer occurs during parallel runs and the regression is covered by a reproducible test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.