Skip to content

Fix deprecated_arg_default message for an already-changed default - #9197

Open
eliem08 wants to merge 2 commits into
Project-MONAI:devfrom
eliem08:fix/deprecated-arg-default-message
Open

eliem08 wants to merge 2 commits into
Project-MONAI:devfrom
eliem08:fix/deprecated-arg-default-message

Conversation

@eliem08

@eliem08 eliem08 commented Oct 20, 2026

Copy link
Copy Markdown

Description

Since #8473 (1.5.1), Orientation and Orientationd warn on every construction that doesn't pass labels:

Current default value of argument `labels=(('L', 'R'), ('P', 'A'), ('I', 'S'))` was changed in version None from `labels=(('L', 'R'), ('P', 'A'), ('I', 'S'))` to `labels=None`.

The decorator is declared without since/replaced, so deprecated_arg_default prints version None, and the "Current default value of argument labels=(('L', 'R'), ...)" prefix suggests the old default is still in effect.

Setting replaced="1.5.1" on the decorators is not a safe fix: when the MONAI version is unknown (0+..., e.g. a source checkout without tags), is_replaced is False, the signature default already equals new_default, and the decorator raises ValueError at import time.

This PR changes only the message for a replaced default:

Default value of argument `labels` was changed from `labels=(('L', 'R'), ('P', 'A'), ('I', 'S'))` to `labels=None`. ...

and includes in version X when replaced is given. Which warnings fire, and when, is unchanged. The stale "raise a DeprecatedError directly" comment is replaced, since that branch only warns.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.

Tests

  • New test_deprecated_arg_default_replaced_message checks the wording with and without a version.
  • tests/utils/test_deprecated.py, tests/transforms/test_orientation.py and test_orientationd.py: 99 passed (98 before plus the new test). The 2 pytest errors on test_orientationd.py (test_resampler_lazy collected as a test, fixture resampler not found) also occur on unmodified dev.
  • black --check and ruff check pass on the changed files.

Orientation(d) declares the labels default change from Project-MONAI#8473 without since
or replaced, so the FutureWarning read "was changed in version None" and
began "Current default value of argument labels=(('L', 'R'), ...)", which
suggests the old default is still in effect. Setting replaced is not an
option: with an unknown MONAI version (e.g. a source checkout without tags)
the signature check raises at import time.

For a replaced default, word the message as "Default value of argument X
was changed [in version V] from ... to ...", omitting the version when it
is not given.

Signed-off-by: eliem08 <emssaadelias@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review.

Walkthrough

deprecated_arg_default now reports a default transition when no version is provided. Replacement warnings identify the argument default, report the old and new values, and include the replacement version when available. Tests cover both warning cases and the Orientation warning.

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

Merge Risk: Minimal · up to 156bc

This change only clarifies the deprecation warning message when an argument default has already changed, and adds tests for it. No behavioral or production risk was identified, so it looks safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the deprecated_arg_default warning message for a default that has already changed. It matches the changeset in monai/utils/deprecate_utils.py and the related tests.
Description check Passed The description covers the problem, the rejected alternative (replaced="1.5.1"), the message change, the test results, and the lint results. It fills in the template's Description and Types of changes…
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: Description check

Explanation

The description covers the problem, the rejected alternative (replaced="1.5.1"), the message change, the test results, and the lint results. It fills in the template's Description and Types of changes sections. The Fixes # line is empty, and the Tests and docs checklist items are not updated. These gaps are minor.

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 57dca89 and 156bc18.

Files selected for processing: 1

  • tests/transforms/test_orientation.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.

vikashg
vikashg previously approved these changes Nov 19, 2026

@vikashg vikashg 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.

Tested against the PR head with 9 new tests for deprecated_arg_default. 2 fail on current dev, and all 9 pass with this change.

With no since or replaced, the warning no longer says "version None" and no longer claims the current default is the old one:

import warnings
from monai.utils import deprecated_arg_default

@deprecated_arg_default("b", old_default="a", new_default="c")
def f(b="c"):
    return b

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always")
    f()
print(w[0].message)
# dev
__main__ f:b: Current default value of argument `b=a` was changed in version None from `b=a` to `b=c`.
# this PR
__main__ f:b: Default value of argument `b` was changed from `b=a` to `b=c`.

Warnings still fire only when the argument isn't passed. Explicit arguments give no warning, msg_suffix and the warning category are kept, and the messages with since and replaced versions are unchanged.

One note: this changes warning text for the two in-repo callers in monai/transforms/spatial/, so anything matching the old text would need updating.

Otherwise LGTM.

@eliem08

eliem08 commented Nov 19, 2026

Copy link
Copy Markdown
Author

Thanks for the review, and for testing it against the PR head.

I checked the two callers (Orientation and Orientationd in monai/transforms/spatial/): nothing in the repo matches the old warning text — the only hits are the new test's own assertions that the old phrasing is gone, and no test asserts warning text for either caller. The Orientation tests also pass identically before and after the change (32 passed; the 2 failures on test_ornt_meta_12/13 are a pre-existing nibabel tie-break, identical on unmodified dev). So nothing needs updating on that note.

I've also pushed a follow-up commit adding a test that locks in the new message on the real Orientation caller. Otherwise I'll leave merging to you.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants