Repository navigation
Find discriminated union sites with one iterator and keep the tag passes' run state in one tag plan - #5454
Conversation
…ses' run state in one tag plan
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
TagPlan state and reuse snapshot src/datamodel_code_generator/parser/_tag_plan.py, src/datamodel_code_generator/parser/base.py, src/datamodel_code_generator/parser/_passes/structure.py, src/datamodel_code_generator/parser/_passes/plans.py, src/datamodel_code_generator/parser/_facts.py, src/datamodel_code_generator/parser/_passes/_shared.py |
Adds shared union-site and tag-plan data. Parser initializes the plan, and structure processing records declared union tags in its reuse snapshot. |
Discriminator pass processing src/datamodel_code_generator/parser/_passes/modules.py |
Discriminator passes discover union sites and use TagPlan for inline variants, discriminator tags, collapsed variants, reused fields, and deferred unions. |
Cross-module and finish-pass consumers src/datamodel_code_generator/parser/_passes/cross_module.py, src/datamodel_code_generator/parser/_passes/imports.py, src/datamodel_code_generator/parser/_passes/_state.py, src/datamodel_code_generator/parser/_passes/_tables.py |
Cross-module and finish passes read opted-out models, tag warnings, and reused tag fields from TagPlan rather than run-level or parser-owned state. |
Layout planning and architecture references src/datamodel_code_generator/parser/_passes/plans.py, docs/architecture.md, scripts/check_architecture_boundaries.py |
Layout flattening derives possible tag names from union sites. Architecture documentation and the boundary check reference and permit the tag-plan module. |
Priority:
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Refactor
Possibly related issues
#5421— The pull request updates discriminator-tag architecture documentation, which is the subject of this issue.#5361— The pull request centralizes shared-union tag records inTagPlan; the issue concerns tag assignment for variants used by multiple unions.
Possibly related PRs
- datamodel-code-generator/datamodel-code-generator#5259 — This pull request refactors the discriminator processing that PR
#5259moved intomodules.py. - datamodel-code-generator/datamodel-code-generator#5197 — This pull request replaces
find_possible_tag_nameswith union-site-based tag-name planning. - datamodel-code-generator/datamodel-code-generator#5381 — Both pull requests change inline-variant and reused
msgspectag state.
Merge Risk: 
Minimal · previous review afdb0
-
The shared tag-plan refactor has no identified merge-blocking regression and is mergeable subject to normal checks.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 95.65% 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 23 functions across 10 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.
Comment @coderabbitai help to get the list of available commands.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
# Conflicts: # docs/architecture.md # docs/llms-full.txt # src/datamodel_code_generator/parser/_facts.py # src/datamodel_code_generator/parser/_passes/_tables.py # src/datamodel_code_generator/parser/_passes/imports.py # src/datamodel_code_generator/parser/_passes/modules.py # src/datamodel_code_generator/parser/_passes/plans.py
# Conflicts: # docs/architecture.md # docs/llms-full.txt
Breaking Change AnalysisResult: No breaking changes detected Reasoning: This PR is an internal refactor that gathers the discriminator tag state into a new private module parser/_tag_plan.py with a TagPlan record and the helpers UnionSite, iter_union_sites, declared_union_tags and possible_tag_names. It replaces six private Parser attributes with one _tag_plan attribute and moves the opted_out list off the pipeline run object. It moves find_possible_tag_names, _union_tags, record_reused_variant_tag_field and _VariantDiscriminatorTags from the private _passes modules into the new module with the same logic, and rewrites the discriminator field loops to use a shared site iterator with the same conditions and order. The rest is docs, architecture-check scripts and new legacy row bookkeeping. Every removed symbol is private (underscore-prefixed or in the private _passes package), so no CLI option, public Python API, template or Python version support changes. The variant-tag warning keeps its text and still fires once per variant. The accepted behaviour-diff cells all concern allOf schemas whose parts admit no object, which the gate attributes to an earlier PR; this diff does not touch allOf handling, so they most likely come from earlier merges since the last release. The other cells are both-fail or crash-fix, which do not change default behaviour. This analysis was produced by the release draft workflow |
|
🎉 Released in 0.88.0 This PR is now available in the latest release. See the release notes for details. |
Summary by CodeRabbit