Skip to content

Pass one module import target to the reference import functions - #6706

Merged
Koudai Aono (koxudaxi) merged 1 commit into
dry-04from
dry-05
Nov 11, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
dry-04from
dry-05

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor
    • Streamlined how imports and cross-module references are handled across generated models, including references involving renamed types, copied fields, and enum members.
    • No user-facing behavior changes are noted.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The import-binding APIs now accept a ModuleImportTarget that groups module import and naming state. Parser passes construct and pass this target for reference imports, reference reimports, and root-model operations.

Changes: Module import binding refactor

Layer / File(s) Summary
Define the module import target
src/datamodel_code_generator/parser/_passes/_state.py, src/datamodel_code_generator/parser/_passes/_import_binding.py, src/datamodel_code_generator/parser/_passes/modules.py
ModuleImportsView defines shared module import properties. ModuleImportTarget groups import and module-naming state and constructs a target from module and scope views.
Refactor import-binding operations
src/datamodel_code_generator/parser/_passes/_import_binding.py, docs/architecture.md
Reference registration, expression updates, and stale-reference reimports accept ModuleImportTarget. The set_reference_expressions and reimport_references wrappers are removed. The architecture documentation names the updated APIs.
Update parser call sites
src/datamodel_code_generator/parser/_passes/cross_module.py, src/datamodel_code_generator/parser/_passes/imports.py, src/datamodel_code_generator/parser/_passes/modules.py, src/datamodel_code_generator/parser/_passes/render_prep.py
Cross-module, module, hidden-submodule, and inherited-field-copy paths construct or pass ModuleImportTarget to the updated import-binding APIs. InheritedFieldCopies.model_path_to_module_name now has type dict[str, str].

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

Merge Risk: Minimal · up to 418dd

This refactor groups the import-binding arguments into one target object without changing behavior. No concrete risks were found, so it is ready to merge after the usual checks.

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 summarizes the main change: passing one module import target to reference import functions.
Docstring Coverage Passed Docstring coverage is 94.44% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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 94.44% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 18 functions across 6 files. (1 skipped: 1 unsupported.)

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fb7094d and 418ddca.

Files ignored due to path filters: 1

  • docs/llms-full.txt is excluded by none and included by none
Files selected for processing: 7

  • docs/architecture.md
  • src/datamodel_code_generator/parser/_passes/_import_binding.py
  • src/datamodel_code_generator/parser/_passes/_state.py
  • src/datamodel_code_generator/parser/_passes/cross_module.py
  • src/datamodel_code_generator/parser/_passes/imports.py
  • src/datamodel_code_generator/parser/_passes/modules.py
  • src/datamodel_code_generator/parser/_passes/render_prep.py

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

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 10, 2026 23:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T23:43:08.476464Z 418ddca Draft marked ready
ℹ️ 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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 10, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 95.96%

2 warnings

⚠️ 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

⚠️ 53 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 53 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_target_render[client-small] 62.5 ms 21.9 ms ×2.9
⚡ test_perf_target_render[fastapi-small] 34.4 ms 14.6 ms ×2.4
⚡ test_perf_client_calls[async] 48.7 ms 20.7 ms ×2.4
⚡ test_perf_client_calls[sync] 43.5 ms 19.3 ms ×2.3
⚡ test_perf_load_pyproject_config[mapping-None] 247.2 µs 111.3 µs ×2.2
⚡ test_perf_load_pyproject_config[mapping-multiple] 265.4 µs 120.1 µs ×2.2
⚡ test_perf_load_pyproject_config[config-multiple] 264.1 µs 120.2 µs ×2.2
⚡ test_perf_load_pyproject_config[config-None] 240 µs 110.3 µs ×2.2
⚡ test_perf_large_models_dataclass_builtin 1,656 ms 775.5 ms ×2.1
⚡ test_perf_graphql_style_pydantic_v2 1,000.9 ms 474.3 ms ×2.1
⚡ test_perf_simple_pydantic_v2_field_construction 12.4 ms 6 ms ×2.1
⚡ test_perf_large_models_pydantic_v2 4.2 s 2 s ×2.1
⚡ test_perf_pydantic_field_name_resolution 2.7 ms 1.3 ms ×2
⚡ test_perf_simple_msgspec_unset_field_rendering 596.1 ms 291.5 ms ×2
⚡ test_perf_unique_items_runtime_scalar_validation 3.1 ms 1.5 ms ×2
⚡ test_perf_extreme_large_schema 17.3 s 8.6 s ×2
⚡ test_perf_scalar_root_collapsed_builtin 247.5 ms 122.9 ms ×2
⚡ test_perf_aws_style_openapi_pydantic_v2 2.7 s 1.3 s ×2
⚡ test_perf_duplicate_names 1,194.5 ms 597 ms ×2
⚡ test_perf_local_reference_file_resolution 167.8 ms 83.9 ms +99.98%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing dry-05 (418ddca) with main (f478c79)2

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. ↩

  2. No successful run was found on dry-04 (fb7094d) during the generation of this report, so main (f478c79) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@koxudaxi
Koudai Aono (koxudaxi) merged commit 1232d9f into main Nov 11, 2026
42 of 144 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR is an internal refactor of the private parser passes package (_import_binding, _state, cross_module, imports, modules, render_prep). It adds a ModuleImportTarget record that bundles the module imports, resolver, module names, init flag, internal modules and shared imports, adds a ModuleImportsView protocol, and removes the private helpers set_reference_expressions and reimport_references. Callers now use import_references and reimport_module_references directly. The shared imports passed in are still the parser imports, which is the same value the host imports gave before, so the logic is unchanged. The only other changes are doc text in architecture.md and llms-full.txt. Every touched name lives in underscore-prefixed internal modules and is not public Python API, and no CLI options, templates, defaults, Python version support or error handling changed. The behaviour diff gate lists only both-fail cells, with no accepted or violation cells, so generated output with default options is the same as in release 0.92.0.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.93.0

This PR is now available in the latest release. See the release notes for details.

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