Repository navigation
Decide the constraint applicability of every field form, render drop and literal check in one home - #5473
Conversation
… decisions through the constraint applicability table
# Conflicts: # docs/architecture.md # docs/llms-full.txt
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| 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:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Refactor
Possibly related issues
- datamodel-code-generator/datamodel-code-generator#4846: The change centralizes constraint decisions for field forms and nested constraint enforcement, which overlaps constrained primitives in unions and arrays.
- datamodel-code-generator/datamodel-code-generator#5078: The change centralizes applicability decisions for fields and nested values, which overlaps pattern handling for dictionary values.
- datamodel-code-generator/datamodel-code-generator#4747: The change centralizes literal constraint checks and msgspec metadata selection.
- datamodel-code-generator/datamodel-code-generator#4493: The change centralizes constraint applicability for rendered field types, including literal and non-matching types.
Possibly related PRs
- datamodel-code-generator/datamodel-code-generator#5352: Both changes determine which constraints remain with
Literalannotations. - datamodel-code-generator/datamodel-code-generator#5445: Both changes centralize numeric constraint applicability and representability decisions.
- datamodel-code-generator/datamodel-code-generator#5396: Both changes cover decimal field forms and
multipleOfconstraints.
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: 
5
-
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.
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 improve performance by 44.62%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Breaking Change AnalysisResult: 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 |
|
🎉 Released in 0.88.0 This PR is now available in the latest release. See the release notes for details. |
Summary by CodeRabbit
Nonevalues, strict numeric types, and decimal field forms.multipleOfvalues that cannot be represented exactly.