Skip to content

Use TypeIs for reference models#3592

Merged
gaborbernat merged 1 commit into
mainfrom
agent/reference-typeis
Jul 7, 2026
Merged

Use TypeIs for reference models#3592
gaborbernat merged 1 commit into
mainfrom
agent/reference-typeis

Conversation

@koxudaxi

@koxudaxi koxudaxi commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Refactor
    • Improved internal type checking for model detection, making the codebase more consistent and reliable for future maintenance.
    • No user-facing behavior changes.

@coderabbitai

coderabbitai Bot commented Jul 7, 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: a425a469-d3f4-4190-99f8-9a9a4ce4c988

📥 Commits

Reviewing files that changed from the base of the PR and between 3677f13 and 2b99445.

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

📝 Walkthrough

Walkthrough

Updates _is_data_model helper's return type annotation in reference.py from bool to TypeIs[DataModel], adding an import for DataModel to support type-guard typing. Runtime behavior is unchanged.

Changes

Type Guard Annotation Update

Layer / File(s) Summary
Type guard annotation
src/datamodel_code_generator/reference.py
Imports DataModel and updates _is_data_model's return type annotation from bool to TypeIs[DataModel], functioning as a type guard; no runtime behavior change.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Poem:
A rabbit hopped through typed terrain,
Swapped a bool for a guard-shaped chain,
TypeIs now marks the data's true form,
Two lines changed, calm and warm,
Hop on, reviewer—nothing to strain.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the change to use TypeIs for the reference model type guard.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 agent/reference-typeis

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

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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

@codspeed-hq

codspeed-hq Bot commented Jul 7, 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.

✅ 13 untouched benchmarks
⏩ 98 skipped benchmarks1


Comparing agent/reference-typeis (2b99445) with main (3677f13)

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 Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3677f13) to head (2b99445).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3592   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          164       164           
  Lines        35288     35288           
  Branches      4075      4075           
=========================================
  Hits         35288     35288           
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.

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gaborbernat gaborbernat merged commit a68873f into main Jul 7, 2026
61 checks passed
@gaborbernat gaborbernat deleted the agent/reference-typeis branch July 7, 2026 20:39
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR only changes the return type annotation of the private internal function _is_data_model from bool to TypeIs[DataModel] and adds a TYPE_CHECKING import for DataModel. This is a pure type-hint refinement with no runtime behavior change. The function is private (underscore-prefixed) and not part of the public API. There are no changes to generated code, templates, CLI/Python API, default behavior, Python version support, or error handling. No breaking changes.


This analysis was performed by Claude Code Action

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🎉 Released in 0.68.1

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