Disclaimer: this report is largely written by Claude as I had it go create a minimal reproduction after encountering this bug on an internal codebase. I did manually run mypy and confirm that the outputs/setup here are correct.
$ mypy --num-workers=3 --show-traceback producer.py consumer.py
consumer.py: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 2.2.0+dev.e53693be05a200543a5b00edd2bb82bbf7c12329
consumer.py: note: use --pdb to drop into pdb
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "mypy/build_worker/__main__.py", line 6, in <module>
console_entry()
File "mypy/build_worker/worker.py", line 361, in console_entry
main(sys.argv[1:])
File "mypy/build_worker/worker.py", line 126, in main
serve(server, ctx)
File "mypy/build_worker/worker.py", line 228, in serve
scc_result = process_stale_scc_interface(...)
File "mypy/build.py", line 4869, in process_stale_scc_interface
maybe_load_deps(graph, ascc, manager)
File "mypy/build.py", line 4749, in maybe_load_deps
process_fresh_modules(graph, sorted(prev_scc.mod_ids), manager)
File "mypy/build.py", line 4703, in process_fresh_modules
graph[id].fix_cross_refs()
File "mypy/build.py", line 3133, in fix_cross_refs
modules_state.node_fixer.visit_symbol_table(self.tree.names)
File "mypy/fixup.py", line 131, in visit_symbol_table
self.visit_type_info(value._node)
File "mypy/fixup.py", line 71, in visit_type_info
base.accept(self.type_fixer)
File "mypy/types.py", line 1673, in accept
return visitor.visit_instance(self)
File "mypy/fixup.py", line 237, in visit_instance
inst.type = lookup_fully_qualified_typeinfo(...)
File "mypy/fixup.py", line 375, in lookup_fully_qualified_typeinfo
stnode = lookup_fully_qualified(name, modules, raise_on_missing=not allow_missing)
File "mypy/lookup.py", line 56, in lookup_fully_qualified
assert key in names, f"Cannot find component {key!r} for {name!r}"
AssertionError: Cannot find component 'Inner@12' for 'producer.Inner@12'
error: INTERNAL ERROR -- Please try using mypy master on GitHub:
...
Traceback (most recent call last):
File "mypy/build.py", line 1392, in receive_worker_message
return receive(self.workers[idx].conn)
File "mypy/ipc.py", line 481, in receive
raise OSError("No data received")
OSError: No data received
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File ".../bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "mypy/__main__.py", line 16, in console_entry
main()
File "mypy/main.py", line 154, in main
res, messages, blockers = run_build(...)
File "mypy/main.py", line 244, in run_build
res = build.build(...)
File "mypy/build.py", line 422, in build
result = build_inner(...)
File "mypy/build.py", line 537, in build_inner
graph = dispatch(sources, manager, stdout, connect_threads)
File "mypy/build.py", line 4150, in dispatch
process_graph(graph, manager)
File "mypy/build.py", line 4618, in process_graph
done, still_working, results = manager.wait_for_done(graph)
File "mypy/build.py", line 1488, in wait_for_done
return self.wait_for_done_workers(graph)
File "mypy/build.py", line 1507, in wait_for_done_workers
buf = self.receive_worker_message(idx)
File "mypy/build.py", line 1400, in receive_worker_message
raise OSError("Worker N disconnected before sending data (exit code 2)")
OSError: Worker 1 disconnected before sending data (exit code 2)
Three files in one directory.
rm -rf .mypy_cache
uvx --with pydantic mypy --num-workers=3 producer.py consumer.py
Disclaimer: this report is largely written by Claude as I had it go create a minimal reproduction after encountering this bug on an internal codebase. I did manually run mypy and confirm that the outputs/setup here are correct.
Crash Report
mypy --num-workers=Ncrashes withAssertionError: Cannot find component 'X@<lineno>'duringfix_cross_refswhen thepydantic.mypyplugin has synthesized a function-localTypeInfofor acreate_model(...)call, that synthetic class is used as a base of a sibling local class, and another module imports any symbol from the producer module. Serial mode is unaffected. The crash also reproduces against currentmaster(2.2.0+dev, commite53693be0).The
@<lineno>suffix is added by mypy itself insemanal.basic_new_typeinfofor function-scoped synthetic TypeInfos. There is aTODO: clean this up, see #6422next to the mangling code, so this area is already flagged.Traceback
To Reproduce
Three files in one directory.
producer.py:consumer.py:mypy.ini:Run:
Bisection notes
All four conditions are required:
create_model("Inner", __base__=BaseModel, ...)call.Inner. ReturningInnerdirectly (without using it as a base) does not trigger the crash.Inneror its outer class.Worker-count sensitivity on this minimal repro:
--num-workersIndependent of cache format: same crash with
--no-fixed-format-cacheand with--no-sqlite-cache. Disabling thepydantic.mypyplugin makes the crash disappear (at the cost of dynamic-class typing).Your Environment
--num-workers=3mypy.ini: