Skip to content

[mypyc] Record MRO ancestor modules as deps of subclass-defining modules#21743

Merged
p-sawicki merged 4 commits into
python:masterfrom
VaggelisD:mypyc-class-ancestor-deps
Jul 21, 2026
Merged

[mypyc] Record MRO ancestor modules as deps of subclass-defining modules#21743
p-sawicki merged 4 commits into
python:masterfrom
VaggelisD:mypyc-class-ancestor-deps

Conversation

@geooo109

@geooo109 geooo109 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #21742

Mypy's incremental system only recompiles a module when a recorded dependency changes, and a dependency edge to an ancestor's module is created in cases such as an explicit import or a checked expression whose type references that ancestor. A bare subclass definition produces neither, so the transitive ancestors never enter the module's dependency graph.

The goal of this PR is to make the dependency graph reflect what the generated C actually depends on. When compiling with mypyc, a module that defines a class now records the modules defining every ancestor in that class's MRO as indirect dependencies, so an ancestor's interface change reaches the subclass-defining module directly.

Fixes python#21742

Mypy's incremental system only recompiles a module when a recorded
dependency changes, and a dependency edge to an ancestor's module is
created in cases such as an explicit import or a checked expression whose
type references that ancestor. A bare subclass definition produces
neither, so the transitive ancestors never enter the module's dependency
graph.

The goal of this PR is to make the dependency graph reflect what the
generated C actually depends on. When compiling with mypyc, a module that
defines a class now records the modules defining every ancestor in that
class's MRO as indirect dependencies, so an ancestor's interface change
reaches the subclass-defining module directly.
@geooo109
geooo109 force-pushed the mypyc-class-ancestor-deps branch from 5f4468f to c3b4e51 Compare July 17, 2026 12:09
@github-actions

This comment has been minimized.

Comment thread mypy/build.py Outdated
Comment thread mypyc/test-data/run-multimodule.test Outdated
Comment thread mypy/plugin.py
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@p-sawicki p-sawicki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@p-sawicki
p-sawicki merged commit 3d657d6 into python:master Jul 21, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mypyc] Incremental separate compilation misses recompiling subclass-only modules when a transitive base class changes

2 participants