Skip to content

Accept stacklevel in warn_deprecated again - #6802

Merged
Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
restore-warn-deprecated-stacklevel
Nov 13, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
restore-warn-deprecated-stacklevel

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Fixes: #6801

Summary by CodeRabbit

  • Improvements
    • Deprecation warnings now support a caller-specified stack level, with existing behavior retained when none is provided.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T20:23:26.415511Z 0572706 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 Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

warn_deprecated now accepts an optional keyword-only stacklevel. When supplied, it passes that value to warnings.warn; otherwise, it retains the caller-frame default.

Changes: Deprecation warning stack level

Layer / File(s) Summary
Add and validate the stacklevel parameter
src/datamodel_code_generator/deprecations.py, tests/test_deprecations.py
warn_deprecated accepts an optional stacklevel and uses it when supplied. The test checks that stacklevel=1 records one warning with deprecations.py as its filename.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 05727

This restores the stacklevel keyword argument on warn_deprecated, so callers that pass it work again. Calls without it behave as before. No merge risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Accept stacklevel in warn_deprecated again" matches the main change. The PR restores the optional stacklevel keyword argument to warn_deprecated, which the raw summary confirms. The linked …
Linked Issues check Passed [#6801] Requirement: warn_deprecated() must accept stacklevel as in 0.95.0, and the warning must name the frame that stacklevel selects. Without stacklevel, the warning must keep naming the library ca…
Out of Scope Changes check Passed The summary lists changes in two files only: src/datamodel_code_generator/deprecations.py (+9/-3, signature and docstring of warn_deprecated) and tests/test_deprecations.py (+10/-0, one new test for e…
Full details: Title check

Explanation

The title "Accept stacklevel in warn_deprecated again" matches the main change. The PR restores the optional stacklevel keyword argument to warn_deprecated, which the raw summary confirms. The linked issue #6801 asks for the same restoration. The title is specific and names the function and parameter.

Full details: Linked Issues check

Explanation

[#6801] Requirement: warn_deprecated() must accept stacklevel as in 0.95.0, and the warning must name the frame that stacklevel selects. Without stacklevel, the warning must keep naming the library caller. Evidence: the AI-generated summary states that warn_deprecated now takes an optional keyword-only stacklevel. When omitted, it uses _stacklevel_at_caller() as before. When supplied, it passes the value to warnings.warn. At head, tests/test_deprecations.py adds test_warn_deprecated_takes_an_explicit_stacklevel, which calls warn_deprecated("cli.parent-scoped-naming", stacklevel=1) and asserts one warning whose filename is deprecations.py. The existing test_warn_deprecated_points_to_caller still asserts that the default call names the caller file. Limit: the git diff could not be read because changed blobs were missing from the checkout, and the head source of warn_deprecated was cut off by the 16000-byte read limit. The implementation is therefore supported by the summary and the test, not by a direct read of the function body. No automated test was run.

Full details: Out of Scope Changes check

Explanation

The summary lists changes in two files only: src/datamodel_code_generator/deprecations.py (+9/-3, signature and docstring of warn_deprecated) and tests/test_deprecations.py (+10/-0, one new test for explicit stacklevel). Both changes directly implement the #6801 requirement. No unrelated changes appear in the summary. Limit: the full diff could not be read, so the exact hunks were not checked against the summary.

Finishing Touches

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e426c95 and 0572706.

Files selected for processing: 2

  • src/datamodel_code_generator/deprecations.py
  • tests/test_deprecations.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 13, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 8.4%

1 warning

⚠️ 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

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 50 untouched benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_simple_pydantic_v2_field_construction 6.2 ms 7.9 ms -21.09%
❌ test_perf_load_yaml_openapi_large 20.2 ms 23.1 ms -12.2%
⚡ test_perf_unique_items_runtime_scalar_validation 1.6 ms 1.5 ms +10.93%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing restore-warn-deprecated-stacklevel (0572706) with main (e426c95)

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 Nov 13, 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 2c0111e into main Nov 13, 2026
116 of 117 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the restore-warn-deprecated-stacklevel branch November 13, 2026 20:36
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR only changes warn_deprecated in deprecations.py by adding an optional keyword-only stacklevel parameter that defaults to None, and a new test. When stacklevel is not passed, the function still uses _stacklevel_at_caller exactly as before, so existing callers, warning messages, categories and attributed frames are unchanged. No parameters, options, templates or public names were removed, and Python version support is unchanged. The behaviour diff gate does list accepted cells, all about how single-quote regex patterns are written. This PR does not touch pattern or code generation logic, so those cells come from other changes since release 0.95.0 and not from this diff. The rest are both-fail, no-behaviour or crash-fix cells, which do not change behaviour.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

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

warn_deprecated() no longer accepts stacklevel

1 participant