Skip to content

Read variant tags through one TagReading and msgspec clashes in one walk - #6709

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

Koudai Aono (koxudaxi) merged 1 commit into
dry-07from
dry-08

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Union validation warnings now avoid repeating kind conflicts that are already covered by enum or alias conflicts.
  • Refactor
    • Consolidated tag-related union handling. Existing tag-selection behavior remains unchanged.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The tag-plan code now groups tag-reading inputs in TagReading and passes that record through validation and union views. Msgspec union-clash detection now computes enum and kind clashes together and uses both results when generating warnings.

Changes: Tag Reading Refactor

Layer / File(s) Summary
TagReading contract and tag-plan processing
src/datamodel_code_generator/parser/_tag_plan.py
TagReading groups inline variants, union-written state, enum-member tag settings, and merged tags. Tag-selection and site-validation functions now accept the record, and UnionView stores it.
TagReading construction and integration
src/datamodel_code_generator/parser/_passes/modules.py, docs/architecture.md, src/datamodel_code_generator/parser/_tag_plan.py
The parser assembles a TagReading for root-model collapse and discriminator processing. The architecture inventory now names TagReading and omits the removed helper references.

Union Clash Detection

Layer / File(s) Summary
Paired enum and kind clash detection
src/datamodel_code_generator/parser/_passes/imports.py
Union-clash detection computes enum and kind clashes together, excludes clash kinds covered by alias roots, and collects both results for warning generation.

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

Change: Refactor

Possibly related PRs

Suggested labels: breaking-change-analyzed

Merge Risk: Minimal · up to 017f8

No concrete regression remains identified; this change is ready to merge after normal 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 both main changes: consolidating variant-tag reading through TagReading and handling msgspec clashes in one walk.
Docstring Coverage Passed Docstring coverage is 100.00% 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. Documentat…
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 100.00% 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 16 functions across 3 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

Warning

Some tools did not complete. Review the errors below.

LanguageTool

docs/architecture.md

LanguageTool checks are incomplete because the per-file request limit of 5 was reached. Remaining text was skipped; findings from completed checks are retained.

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 04104d6 and 017f8ee.

Files ignored due to path filters: 1

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

  • docs/architecture.md
  • src/datamodel_code_generator/parser/_passes/imports.py
  • src/datamodel_code_generator/parser/_passes/modules.py
  • src/datamodel_code_generator/parser/_tag_plan.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 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:21.200287Z 017f8ee 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 52.44%

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 28.9 ms ×2.2
⚡ test_perf_target_render[fastapi-small] 34.4 ms 17.7 ms +94.01%
⚡ test_perf_simple_msgspec_unset_field_rendering 596.1 ms 335.5 ms +77.68%
⚡ test_perf_client_calls[sync] 43.5 ms 25 ms +73.99%
⚡ test_perf_client_calls[async] 48.7 ms 28.1 ms +73.43%
⚡ test_perf_load_pyproject_config[mapping-multiple] 265.4 µs 154.2 µs +72.13%
⚡ test_perf_load_pyproject_config[mapping-None] 247.2 µs 144.4 µs +71.17%
⚡ test_perf_load_pyproject_config[config-multiple] 264.1 µs 154.5 µs +70.92%
⚡ test_perf_load_pyproject_config[config-None] 240 µs 140.7 µs +70.55%
⚡ test_perf_scalar_root_collapsed_builtin 247.5 ms 151.3 ms +63.53%
⚡ test_perf_target_render[fastapi-large] 10.4 s 6.4 s +61.65%
⚡ test_perf_ordinary_array_constraint_generation 2.7 s 1.7 s +58.12%
⚡ test_perf_local_reference_file_resolution 167.8 ms 107 ms +56.76%
⚡ test_perf_large_models_dataclass_builtin 1.7 s 1.1 s +56.38%
⚡ test_perf_large_models_msgspec 2.4 s 1.5 s +55.36%
⚡ test_perf_large_models_typed_dict[total-false-requiredness] 1,385.7 ms 895.9 ms +54.67%
⚡ test_perf_graphql_style_pydantic_v2 1,000.9 ms 647.6 ms +54.55%
⚡ test_perf_large_models_single_module_stdout 2 s 1.3 s +53.76%
⚡ test_perf_inherited_required_fields[partial-base-first] 1.6 s 1 s +53.75%
⚡ test_perf_inherited_required_fields[partial-derived-first] 1.7 s 1.1 s +53.25%
... ... ... ... ...

ℹ️ 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-08 (017f8ee) 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-07 (04104d6) 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 42295e2 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: This PR is an internal refactor with no behaviour change. Tag-reading parameters (inline_variants, union_written, enum_member_tags, merged_tags) are bundled into a new TagReading record in the private module parser/_tag_plan.py. The parser/_passes/modules.py helpers inline_variant_models and merged_variant_models are replaced by a single tag_reading helper that computes the same values in the same order and still returns no merged tags without the merge-shared-variant-tags option. In parser/_passes/imports.py, the msgspec union-clash detection is reorganised so that _refused_union_clashes returns the Enum clashes and the kind clashes together, and _msgspec_kind_clashes now takes the precomputed Enum clashes instead of recomputing them; the same clashes are filtered the same way. All changed code is in underscore-prefixed private modules, so no public CLI option, Python API, template or default changes, and the doc edits only update internal architecture notes. Every behaviour diff gate cell is both-fail, with no accepted or violation cells, which confirms default output is unchanged.


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