Visitar URL original
Simplify Python version feature checks by koxudaxi · Pull Request #3361 · datamodel-code-generator/datamodel-code-generator · GitHub
Skip to content

Simplify Python version feature checks - #3361

Merged
Koudai Aono (koxudaxi) merged 2 commits into
mainfrom
refactor/format-version-features
Jun 12, 2026
Merged

Koudai Aono (koxudaxi) merged 2 commits into
mainfrom
refactor/format-version-features

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b1312a04-53c9-47f0-ba10-a1f70079311a

📥 Commits

Reviewing files that changed from the base of the PR and between 6192212 and 191862c.

📒 Files selected for processing (1)
  • src/datamodel_code_generator/format.py

📝 Walkthrough

Walkthrough

This PR standardizes the internal implementation of Python version checks in PythonVersion. Three cached property methods (_is_py_312_or_later, _is_py_313_or_later, _is_py_314_or_later) were refactored to use consistent version_key tuple comparisons instead of membership checks, aligning with the existing _is_py_311_or_later pattern.

Changes

Version check standardization

Layer / File(s) Summary
PythonVersion version comparison logic
src/datamodel_code_generator/format.py
_is_py_312_or_later, _is_py_313_or_later, and _is_py_314_or_later cached properties now use version_key >= (major, minor) comparisons rather than excluding target version strings from value membership checks, standardizing with _is_py_311_or_later.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Version checks in harmony, no more scattered ways,
Tuple comparisons now dance in standardized rays,
Python three-twelve through fourteen aligned,
Consistency blooms when the patterns are refined! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring Python version feature checks to use a simpler, standardized comparison pattern instead of string membership checks.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/format-version-features

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 and usage tips.

@codspeed

codspeed Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 11 untouched benchmarks
⏩ 98 skipped benchmarks1


Comparing refactor/format-version-features (07888fc) with main (acc8738)

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. ↩

@koxudaxi
Koudai Aono (koxudaxi) enabled auto-merge (squash) June 12, 2026 14:19
@github-actions

Copy link
Copy Markdown
Contributor

📚 Docs Preview: https://pr-3361.datamodel-code-generator.pages.dev

@koxudaxi
Koudai Aono (koxudaxi) merged commit 773da42 into main Jun 12, 2026
49 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the refactor/format-version-features branch June 12, 2026 17:59
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (acc8738) to head (07888fc).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3361   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          129       129           
  Lines        28563     28563           
  Branches      3449      3449           
=========================================
  Hits         28563     28563           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: PR #3361 changes only src/datamodel_code_generator/format.py, refactoring four private cached_property helpers (_is_py_311_or_later, _is_py_312_or_later, _is_py_313_or_later, _is_py_314_or_later) from value-membership comparisons to tuple comparisons against the pre-existing version_key property (e.g. self.value != self.PY_310.value → self.version_key >= (3, 11)). These are internal helpers, and with the unchanged supported version set (PY_310–PY_314) the new logic produces identical boolean results for every enum member. No public API/CLI options, generated code output, Jinja2 templates, default values/behavior, supported Python versions, or error handling are affected. This is a behavior-preserving internal simplification, not a breaking change.


This analysis was performed by Claude Code Action

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.64.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