Skip to content

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

Open
geooo109 wants to merge 2 commits into
python:masterfrom
VaggelisD:mypyc-class-ancestor-deps
Open

[mypyc] Record MRO ancestor modules as deps of subclass-defining modules#21743
geooo109 wants to merge 2 commits into
python:masterfrom
VaggelisD:mypyc-class-ancestor-deps

Conversation

@geooo109

@geooo109 geooo109 commented Jul 17, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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

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

1 participant