Skip to content

Build module import plans and the name table beside today's imports - #5166

Merged
Koudai Aono (koxudaxi) merged 1 commit into
gr13-graph-sealfrom
rp15a-import-plans
Oct 23, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
gr13-graph-sealfrom
rp15a-import-plans

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Documentation
    • Clarified how module imports and final names are planned, and what the import consistency check verifies.
  • Bug Fixes
    • Expanded import checks to detect mismatched model names, missing or incorrectly bound imports, and unexpected imports. Reports can include counts of compared model names per module.
  • Tests
    • Added coverage confirming that report mode records discrepancies when generated model types, aliases, or imports differ from the plan.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 872784a19e7fb082a347dcd83173b56285db0f12 and 3b2fce7af3c71770501e4325f9d60346daade010.

⛔ Files ignored due to path filters: 3
  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/expected/main/main_general/models_named_outside_the_import_plan.report.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/main_general/module_imports_written_outside_the_import_ledger[report].report.txt is excluded by !tests/data/**/*.txt and included by none
📒 Files selected for processing: 8
  • docs/architecture.md
  • docs/development-contributing.md
  • src/datamodel_code_generator/_checks.py
  • src/datamodel_code_generator/parser/_imports_plan.py
  • src/datamodel_code_generator/parser/_passes/_shared.py
  • src/datamodel_code_generator/parser/base.py
  • tests/main/test_main_general.py
  • tests/main/test_main_general.refs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

📝 Walkthrough

The import ledger now records name-resolution requests and releases. When MODULE_IMPORTS checks are enabled, the parser builds module import plans from final model names and compares planned imports and written names with module output.

Changes: Module import checks

Layer / File(s) Summary
Track import names and resolve targets
src/datamodel_code_generator/parser/_imports_plan.py, src/datamodel_code_generator/parser/_passes/_shared.py, src/datamodel_code_generator/parser/base.py
The ledger records name requests and releases. Reference import resolution is separated from registration. Parser name allocation and release sites use the ledger, and generic-base import paths use a shared helper.
Build and compare module import plans
src/datamodel_code_generator/parser/_imports_plan.py, src/datamodel_code_generator/parser/base.py, src/datamodel_code_generator/_checks.py, docs/architecture.md, docs/development-contributing.md, tests/main/test_main_general.py, tests/main/test_main_general.refs
The parser builds plans from final model names and references, then compares planned imports and written names with ledger replay. The check description and documentation describe the added checks. A test covers discrepancies in model names, aliases, and imports.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Parser
  participant ModuleImportLedger
  participant ModuleImportPlan
  participant MODULE_IMPORTS_check
  Parser->>ModuleImportLedger: Read name events and import entries
  Parser->>ModuleImportPlan: Build plan from final names and references
  MODULE_IMPORTS_check->>ModuleImportPlan: Compare planned names and imports
  MODULE_IMPORTS_check->>ModuleImportLedger: Replay import entries
  MODULE_IMPORTS_check->>MODULE_IMPORTS_check: Record differences and report counts
Loading

Possibly related issues

  • datamodel-code-generator/datamodel-code-generator#4822: The import-plan check can detect a generated reference whose planned import is missing; this change does not add the missing import.
  • datamodel-code-generator/datamodel-code-generator#4823: The plan check compares module imports and references, but the change does not alter import placement behavior.
  • datamodel-code-generator/datamodel-code-generator#5031: The check covers planned model names and imports for references, but the change does not itself correct a TypedDict reference.
  • datamodel-code-generator/datamodel-code-generator#5130: The parser records plans before rendering modules, and the check compares those plans with module output; this change does not remove stale imports.
Merge Risk: ⚪ Minimal · up to 3b2fc

No blocking issue was identified in the import-planning changes; the PR is ready for normal validation and merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: adding module import plans and a name table alongside existing import handling.
Docstring Coverage Passed Docstring coverage is 86.96% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 4 files. (4 skipped: 3 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 86.96% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 4 files. (4 skipped: 3 unsupported, 1 too large.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T23:34:38.970259Z 3b2fce7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b2fce7af3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

@codspeed

codspeed Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 11.99%

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

❌ 1 regressed benchmark
✅ 49 untouched benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_simple_pydantic_v2_field_construction 10.8 ms 12.3 ms -11.99%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing rp15a-import-plans (37f87b5) with gr13-graph-seal (0a3b6fb)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

@koxudaxi
Koudai Aono (koxudaxi) merged commit 2e0ce9b into main Oct 23, 2026
25 of 26 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the rp15a-import-plans branch October 23, 2026 04:16
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR is an internal refactor of import planning. Resolver calls to add and delete_names now go through new ModuleImportLedger methods add_name and release_names, which log the event and forward the same arguments. One call in __change_imported_model_name drops unique=True, which keeps behavior if ModelResolver.add still defaults unique to True, though the diff does not show that signature. The path logic of register_reference_import was split into a new helper, reference_import_target, while its signature and outputs stay the same. The generic base class import module is computed by a new helper that repeats the old inline code. The new import-plan types and the __plan_module_imports step run only when the DATAMODEL_CODE_GENERATOR_CHECK_MODULE_IMPORTS check is on, and nothing is written from the plan, so generated code does not change. That check is an internal test tool and now adds plan comparisons and extra report lines. No CLI options, public API, defaults, templates, Python version support or user-facing error handling changed.


This analysis was produced by the release draft workflow

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant