Skip to content

Decide the number values each output can write in one place, with one int64 range for msgspec - #5445

Merged
Koudai Aono (koxudaxi) merged 3 commits into
mainfrom
dry-a8
Oct 29, 2026
Merged

Koudai Aono (koxudaxi) merged 3 commits into
mainfrom
dry-a8

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of numeric constraints in generated models, including large integers, values that cannot be represented exactly as floating-point numbers, and non-finite bounds.
    • Generation now respects each output format’s supported integer range and treatment of non-finite bounds.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-28T19:59:31.661248Z 39d89ea 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.

@coderabbitai

coderabbitai Bot commented Oct 28, 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 0745dfa and 39d89ea.

Files selected for processing: 6
  • src/datamodel_code_generator/_constraint_applicability.py
  • src/datamodel_code_generator/model/_decisions/tag_value.py
  • src/datamodel_code_generator/model/msgspec.py
  • src/datamodel_code_generator/model/pydantic_base.py
  • src/datamodel_code_generator/parser/_passes/imports.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

Numeric constraint normalization and integer-range checks now use shared output applicability rules. The Pydantic and msgspec generators use shared helpers for numeric constraints, and msgspec integer checks use a shared signed 64-bit range.

Changes: Numeric Constraint Handling

Layer / File(s) Summary
Shared numeric constraint rules
src/datamodel_code_generator/_constraint_applicability.py, src/datamodel_code_generator/types.py
Output metadata now specifies accepted integer ranges and non-finite bound handling. Shared helpers provide numeric conversion, integer-range checks, and strict constraint normalization.
Generator constraint normalization
src/datamodel_code_generator/model/msgspec.py, src/datamodel_code_generator/model/pydantic_base.py
Both generators use shared numeric keywords and strict constraint normalization. Msgspec uses the shared output rules when it checks integer constraints.
Msgspec integer-range checks
src/datamodel_code_generator/model/_decisions/tag_value.py, src/datamodel_code_generator/parser/_passes/imports.py
Tag-value refusal and wide-integer detection use the shared msgspec integer-range check instead of local signed 64-bit bounds.

Priority: Low

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

Change: Bug fix

Merge Risk: Minimal · previous review 39d89

The shared numeric rules preserve existing constraint handling and msgspec integer limits. No actionable merge-blocking issue remains; 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 clearly describes the main change: centralizing output number-value decisions and defining one int64 range for msgspec.
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 11 functions across 6 files.

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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 53.18%

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 495.2 ms 274.8 ms +80.18%
⚡ test_perf_client_calls[sync] 42.1 ms 24 ms +75.84%
⚡ test_perf_scalar_root_collapsed_builtin 213.3 ms 121.9 ms +75.03%
⚡ test_perf_client_calls[async] 46.7 ms 26.8 ms +74.42%
⚡ test_perf_ordinary_array_constraint_generation 2 s 1.2 s +70.67%
⚡ test_perf_local_reference_file_resolution 132.3 ms 79.3 ms +66.88%
⚡ test_perf_large_models_typed_dict[legacy-requiredness] 1,148.4 ms 692 ms +65.96%
⚡ test_perf_large_models_single_module_stdout 1,554.3 ms 940.5 ms +65.25%
⚡ test_perf_large_models_msgspec 1.9 s 1.2 s +65.03%
⚡ test_perf_large_models_dataclass_builtin 1,363.7 ms 827 ms +64.9%
⚡ test_perf_large_models_typed_dict[total-false-requiredness] 1,142.7 ms 696 ms +64.18%
⚡ test_perf_large_models_pydantic_v2_builtin 1,343 ms 823.1 ms +63.17%
⚡ test_perf_false_reference_validation 262.8 ms 161.1 ms +63.11%
⚡ test_perf_large_models_pydantic_v2_noformat 1,359.3 ms 837.5 ms +62.29%
⚡ test_perf_load_pyproject_config[config-multiple] 381.2 µs 237.2 µs +60.68%
⚡ test_perf_load_pyproject_config[mapping-multiple] 382.1 µs 237.8 µs +60.68%
⚡ test_perf_load_pyproject_config[mapping-None] 370.2 µs 230.9 µs +60.3%
⚡ test_perf_load_pyproject_config[config-None] 366.5 µs 229 µs +60.06%
⚡ test_perf_large_models_pydantic_v2_builtin_double_quotes 1,404 ms 892.6 ms +57.28%
⚡ test_perf_inherited_required_fields[required-base-first] 624 ms 396.8 ms +57.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-a8 (8b973fa) with main (50e25de)

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 28, 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 d87f582 into main Oct 29, 2026
164 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR is an internal refactor that moves the number-constraint helpers into _constraint_applicability. It adds saturating_float, exact_float, is_non_finite, non_finite_written, int_beyond_values, int_constraint_beyond_values, NUMBER_FIELD_KEYWORDS, and the int_values and drops_non_finite_bounds rows of OutputKeywords. Only the msgspec output sets those rows, to the signed 64-bit range and True; the base and Pydantic outputs keep None and False. The two private _get_strict_field_constraint methods are replaced by one shared strict_number_constraint function in types.py that keeps the same logic. msgspec still drops non-finite bounds, Pydantic still keeps them, and the per-keyword int64 limits rebuilt from the range match the removed _INT_META_LIMITS table exactly: gt up to 263-2, lt from -263+1, the rest across the full range. The Struct tag, Enum and Literal int range, and float-precision checks give the same results as before. Every removed name is private and public helpers such as normalize_integer_constraint are kept, so there are no CLI, public API, template or Python version changes. The accepted cells in the behaviour diff gate cover allOf schemas that now become root models, which the gate notes credit to the earlier PR 5401 and which this diff does not touch; the crash-fix cell for an import named like a builtin package is also unrelated, so this PR causes no default-output 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.

2 participants