Skip to content

Remove the duplicates in the leaf modules: runtime type expressions, Python literals, sources, regex syntax and graphs - #5494

Merged
Koudai Aono (koxudaxi) merged 2 commits into
dry-r04from
dry-r07
Oct 29, 2026
Merged

Koudai Aono (koxudaxi) merged 2 commits into
dry-r04from
dry-r07

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor
    • Simplified internal processing across model generation, type handling, schema loading, and code rendering while retaining existing conversion behavior.
    • Consolidated runtime annotation conversion and remote lock updates, and aligned dependency ordering and validation with shared logic.
    • These changes focus on internal consistency; no new user-facing features are described in this release.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 7227524 and 6d882ec.

Files selected for processing: 15
  • src/datamodel_code_generator/_internal_utils.py
  • src/datamodel_code_generator/_openapi_codec_plan.py
  • src/datamodel_code_generator/_python_type_annotation_codec.py
  • src/datamodel_code_generator/_python_type_import_registry.py
  • src/datamodel_code_generator/_python_type_runtime.py
  • src/datamodel_code_generator/_reference_graph.py
  • src/datamodel_code_generator/_regex_syntax.py
  • src/datamodel_code_generator/_scc.py
  • src/datamodel_code_generator/_source.py
  • src/datamodel_code_generator/_target_render.py
  • src/datamodel_code_generator/dynamic.py
  • src/datamodel_code_generator/parser/mcp.py
  • src/datamodel_code_generator/python_literal.py
  • src/datamodel_code_generator/remote_lock.py
  • src/datamodel_code_generator/validators.py

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

Walkthrough

The pull request consolidates internal type conversion, literal rendering, source decoding, and validation logic. It also updates remote lock handling, dynamic model rebuilding, graph ordering, and regular-expression analysis.

Changes: Type processing and plan rendering

Layer / File(s) Summary
Type expression conversion
src/datamodel_code_generator/_internal_utils.py, src/datamodel_code_generator/_openapi_codec_plan.py, src/datamodel_code_generator/_python_type_annotation_codec.py, src/datamodel_code_generator/_python_type_import_registry.py, src/datamodel_code_generator/_python_type_runtime.py, src/datamodel_code_generator/parser/mcp.py
Type annotation and runtime conversion use consolidated logic. Backport versions derive from the stable-type introduction table. The changes also remove a fallback match arm and unused imports.
Parameter-plan serialization
src/datamodel_code_generator/_target_render.py
Parameter-plan rendering iterates dataclass fields, omits values that match declared defaults, and renders field-plan values through field_plan.

Python literal rendering

Layer / File(s) Summary
Container rewriting and rendering
src/datamodel_code_generator/python_literal.py
Runtime-expression rewriting handles exact built-in containers recursively. Trusted and untrusted rendering share container formatting logic, with their existing distinct set-ordering policies.

Source parsing and cache

Layer / File(s) Summary
Source decoding and mapping validation
src/datamodel_code_generator/_source.py
Parser-source decoding uses one function with optional digest-based caching. JSON parsing falls back to YAML on JSON decode errors, and mapping checks use a shared helper.

Remote lock handling

Layer / File(s) Summary
Remote URL identity and response recording
src/datamodel_code_generator/remote_lock.py
URL validation and identity use the parsed scheme. Response recording combines missing-entry and body-mismatch handling, replacing entries in update mode.

Dynamic model handling

Layer / File(s) Summary
Model rebuilding and extraction
src/datamodel_code_generator/dynamic.py
Single- and multi-module execution rebuild every BaseModel subclass. Model extraction applies private-name filtering directly while retaining its model and enum selection conditions.

Graph ordering and components

Layer / File(s) Summary
Dependency ordering and SCC selection
src/datamodel_code_generator/_reference_graph.py, src/datamodel_code_generator/_scc.py
Reference dependency ordering delegates to GroupGraph. SCC filtering uses a sorted comprehension, while traversal behavior remains unchanged.

Regular-expression syntax analysis

Layer / File(s) Summary
Regex scanning and pattern construction
src/datamodel_code_generator/_regex_syntax.py
Regex patterns reuse shared expressions. Lookalike checks reject lookarounds, and short lookahead lists use pairwise_patterns.

Identifier and path validation

Layer / File(s) Summary
Normalized identifier and path checks
src/datamodel_code_generator/validators.py
Identifier and keyword checks use normalized names. Dotted paths and import paths use the safe public type name helper.

Priority: Low

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

Change: Refactor

Merge Risk: Minimal · up to 6d882

The consolidation has no established merge-blocking regression and is mergeable subject to normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 76.32% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: deduplicating code across leaf modules. It names the primary affected areas and matches the pull request objectives.
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 76.32% which is insufficient. 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 38 functions across 13 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 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 29, 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-29T06:48:58.230992Z 6d882ec 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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 97.11%

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

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

⚡ 52 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_client_calls[async] 48.4 ms 19.8 ms ×2.4
⚡ test_perf_client_calls[sync] 43.7 ms 18.3 ms ×2.4
⚡ test_perf_load_pyproject_config[mapping-None] 376.8 µs 170.5 µs ×2.2
⚡ test_perf_simple_msgspec_unset_field_rendering 521.1 ms 236.6 ms ×2.2
⚡ test_perf_load_pyproject_config[config-None] 371.5 µs 169.3 µs ×2.2
⚡ test_perf_graphql_style_pydantic_v2 896.5 ms 408.9 ms ×2.2
⚡ test_perf_load_pyproject_config[config-multiple] 385.8 µs 177.4 µs ×2.2
⚡ test_perf_load_pyproject_config[mapping-multiple] 383 µs 177.6 µs ×2.2
⚡ test_perf_duplicate_names 1,100.9 ms 514.3 ms ×2.1
⚡ test_perf_complex_refs 2.2 s 1 s ×2.1
⚡ test_perf_deep_nested 5.9 s 2.8 s ×2.1
⚡ test_perf_extreme_large_schema 16.8 s 8 s ×2.1
⚡ test_perf_local_reference_file_resolution 128.7 ms 60.9 ms ×2.1
⚡ test_perf_all_options_enabled 6.3 s 3 s ×2.1
⚡ test_perf_pydantic_field_name_resolution 1,995.1 µs 947.6 µs ×2.1
⚡ test_perf_multiple_files_input 4 s 1.9 s ×2.1
⚡ test_perf_unique_items_runtime_scalar_validation 3.1 ms 1.5 ms ×2.1
⚡ test_perf_aws_style_openapi_pydantic_v2 2.3 s 1.1 s ×2.1
⚡ test_perf_false_reference_validation 266 ms 128.3 ms ×2.1
⚡ test_perf_stripe_style_pydantic_v2 2.2 s 1 s ×2.1
... ... ... ... ...

ℹ️ 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-r07 (6d882ec) with dry-r04 (7227524)

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 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koxudaxi
Koudai Aono (koxudaxi) merged commit eaf371a into main Oct 29, 2026
164 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the dry-r07 branch October 29, 2026 07:10
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The diff is an internal refactor that keeps behaviour the same. It merges duplicated helpers in _python_type_runtime into one function and keeps the public python_callable_expr_from_runtime_args. It builds the typing_extensions backport table from the existing version table, shares counted-repetition and literal regex constants, sends two-pattern lookahead joining through pairwise_patterns, and shortens the SCC, reference-graph, source-loading, remote-lock, python_literal, target_render parameter_plan and validators code. Only private names are removed: _should_extract_model_name, _stringify_untrusted_value, _rebuild_runtime_container, _EMPTY_SET, _MIN_DOTTED_PATH_PARTS, _PLAN_DEFAULTS, and the noqa re-exports of _local_definition_ref_name and _rewrite_local_definition_ref from parser.mcp. No CLI option, public API, template variable, default value, Python version or error message changes. The remote lock code drops scheme lowercasing, but urlsplit already lowercases the scheme, and the http/https check still runs in _split_remote_url. In dynamic.py, model_rebuild drops the pydantic_generic_metadata check, but every pydantic v2 BaseModel already has that attribute. The behaviour gate lists accepted cells, but their notes put them on an earlier allOf change where an allOf whose parts admit no object becomes a root model or alias. This diff does not touch that logic. The other cells are both-fail or crash-fix, so they show no default-output change from this PR.


This analysis was produced by the release draft workflow

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🎉 Released in 0.88.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