Skip to content

Decide the constraint applicability of every field form, render drop and literal check in one home - #5473

Merged
Koudai Aono (koxudaxi) merged 6 commits into
dry-r7from
dry-a9b
Oct 29, 2026
Merged

Koudai Aono (koxudaxi) merged 6 commits into
dry-r7from
dry-a9b

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved constraint handling in generated models, including literal and None values, strict numeric types, and decimal field forms.
    • Better preserved constraints when types enforce them, while avoiding redundant or unsupported constraints in generated output.
    • Improved handling of float multipleOf values that cannot be represented exactly.

@coderabbitai

coderabbitai Bot commented Oct 29, 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 0aa791c and c65fa26.

Files ignored due to path filters: 1
  • docs/llms-full.txt is excluded by none and included by none
Files selected for processing: 10
  • docs/architecture.md
  • scripts/decision_homes.toml
  • src/datamodel_code_generator/_constraint_applicability.py
  • src/datamodel_code_generator/_recommend/_signals.py
  • src/datamodel_code_generator/model/base.py
  • src/datamodel_code_generator/model/msgspec.py
  • src/datamodel_code_generator/model/pydantic_base.py
  • src/datamodel_code_generator/model/pydantic_v2/types.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • src/datamodel_code_generator/types.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.

Walkthrough

The change centralizes constraint applicability options and helper decisions, then uses them in JSON Schema parsing and model-generation paths. It also updates the architecture record and decision-home allowlist to reflect the changed adapters.

Changes: Constraint applicability

Layer / File(s) Summary
Shared applicability options and helpers
src/datamodel_code_generator/_constraint_applicability.py, src/datamodel_code_generator/types.py, docs/architecture.md, scripts/decision_homes.toml
Adds ConstraintOptions and shared helpers for constraint enforcement, literal checks, field forms, render omissions, None types, and inexact float divisors. DataTypeManager exposes the options.
JSON Schema constraint routing
src/datamodel_code_generator/parser/jsonschema.py, scripts/decision_homes.toml
Uses shared helpers to determine which constraints literals and enforcing types satisfy, and whether constraints are written beside literals.
Model and recommendation adapters
src/datamodel_code_generator/model/base.py, src/datamodel_code_generator/model/pydantic_base.py, src/datamodel_code_generator/model/pydantic_v2/types.py, src/datamodel_code_generator/model/msgspec.py, src/datamodel_code_generator/_recommend/_signals.py, scripts/decision_homes.toml
Routes render-drop, None-field, numeric field-form, float-divisor, and literal metadata decisions through shared applicability logic. Recommendation checks use shared constraint keyword sets.

Priority: Low

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

Change: Refactor

Possibly related issues

Possibly related PRs

Suggested labels: breaking-change-analyzed

Merge Risk: Minimal · previous review c65fa

Constraint decisions are centralized across parsing and model generation. No concrete merge-blocking risk is established; merge after normal checks pass.

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 is a single sentence and names the main theme of the changeset: a shared constraint-applicability table now decides constraint behavior for field forms, render drops, and literal checks. The…
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: Title check

Explanation

The title is a single sentence and names the main theme of the changeset: a shared constraint-applicability table now decides constraint behavior for field forms, render drops, and literal checks. The raw summary confirms this. New helpers in _constraint_applicability.py (render_drop, literal_met_keywords, field_form_zero_bound, decimal_field_form) are used by model/base.py, msgspec.py, pydantic_base.py, pydantic_v2/types.py, and parser/jsonschema.py, and scripts/decision_homes.toml is updated to match. The title is long (98 characters, 16 words) and uses internal jargon such as "home", but it still describes the primary change accurately. The PR objectives also describe routing these decisions through one applicability table.

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 23 functions across 7 files. (3 skipped: 2 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

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 🔄 Running since 2026-10-29T02:25:22.272487Z c65fa26 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 44.62%

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_simple_msgspec_unset_field_rendering 511.5 ms 284.5 ms +79.79%
⚡ test_perf_client_calls[sync] 42.8 ms 24.6 ms +74.31%
⚡ test_perf_client_calls[async] 47.9 ms 27.6 ms +73.55%
⚡ test_perf_load_pyproject_config[mapping-multiple] 390.7 µs 237.5 µs +64.54%
⚡ test_perf_scalar_root_collapsed_builtin 209.3 ms 128 ms +63.53%
⚡ test_perf_load_pyproject_config[mapping-None] 376.5 µs 230.4 µs +63.42%
⚡ test_perf_load_pyproject_config[config-None] 369.3 µs 226.4 µs +63.1%
⚡ test_perf_load_pyproject_config[config-multiple] 382.3 µs 238.2 µs +60.52%
⚡ test_perf_local_reference_file_resolution 128.9 ms 81.1 ms +58.9%
⚡ test_perf_ordinary_array_constraint_generation 1.9 s 1.2 s +53.27%
⚡ test_perf_false_reference_validation 265.3 ms 173.4 ms +53.01%
⚡ test_perf_large_models_single_module_stdout 1,496.3 ms 978.5 ms +52.93%
⚡ test_perf_inherited_required_fields[partial-derived-first] 1,094.7 ms 718.2 ms +52.42%
⚡ test_perf_large_models_msgspec 1.9 s 1.3 s +51.15%
⚡ test_perf_large_models_pydantic_v2_builtin 1,261.8 ms 834.9 ms +51.12%
⚡ test_perf_inherited_required_fields[partial-base-first] 991.8 ms 662.1 ms +49.8%
⚡ test_perf_large_models_pydantic_v2_builtin_double_quotes 1,305.4 ms 874.4 ms +49.29%
⚡ test_perf_large_models_pydantic_v2_noformat 1,276.4 ms 856.4 ms +49.03%
⚡ test_perf_large_models_pydantic_v2 3.9 s 2.6 s +48.55%
⚡ test_perf_large_models_typed_dict[total-false-requiredness] 1,119.1 ms 762.5 ms +46.78%
... ... ... ... ...

ℹ️ 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-a9b (494ef9c) with dry-r7 (0aa791c)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-r7 (6859273) during the generation of this report, so 8cac773 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 ed5d3e3 into main Oct 29, 2026
29 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the dry-a9b branch October 29, 2026 03:18
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor that moves the reading of --omit-redundant-constraints and --use-decimal-in-field-forms into the constraint table. It adds a ConstraintOptions record and pure helpers to the private _constraint_applicability module: enforced_keywords, literal_enforces_every_keyword, writes_beside_literal, field_form_zero_bound, decimal_field_form, strict_decimal_multiple, render_drop, none_type_keywords, literal_met_keywords and inexact_float_divisor. It also adds a DataTypeManager.constraint_options property that the parser, the Pydantic v2 type manager and the msgspec and Pydantic field classes now call. I compared each replaced code path line by line and found no change in what it produces. The negated exact-divisor check matches the new inexact_float_divisor. The per-keyword literal check in msgspec gives the same result as literal_met_keywords with unmet_too. The recursive union intersection gives the same result as the flattened enforcing leaves. The zero-bound and Decimal field-form conditions keep the same option gating. The AnyUrl and self-reference drops return the same outcomes through render_drop. The removed items are private: the _can_apply_constraints property, _is_exact_float_divisor, _is_decimal_multiple, _enforced_constraint_keywords, _literal_meets and the _ZERO_BOUND_KEYWORDS constants. None of them is a CLI option, public Python API or documented template variable. The rest of the diff touches docs and the decision_homes.toml audit file only. The behaviour diff gate does list accepted cells, but they all describe allOf schemas whose parts admit no object switching from an empty object model to a RootModel or alias. The notes credit that change to an earlier PR, and this diff does not touch allOf handling at all. The gate compares against the last release, so those cells add up changes from earlier PRs rather than coming from this one. The remaining cells are both-fail or crash-fix, which do not change behaviour. I found no CLI, API, template, default-behaviour, Python-version or error-handling change.


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