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 identifies the argument default and its old and new values in replacement warnings. The warning includes a replacement version only when one is set. Tests check warning text with and without a version, including the warning emitted when constructing Orientation.

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

Merge Risk: Minimal · up to ea53f

This change only updates the wording of a default-change deprecation warning and adds tests for it. Behavior and timing of the warning are unchanged, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the deprecated_arg_default warning text for a default that has already changed. The changeset matches this: the message now says the default 'was changed' and includes…
Description check Passed The description follows the template: it has a Description section explaining the bug (version None, misleading 'current default' prefix), the rejected alternative (replaced='1.5.1' fails on unknown v…
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: Title check

Explanation

The title names the main change: the deprecated_arg_default warning text for a default that has already changed. The changeset matches this: the message now says the default 'was changed' and includes 'in version X' only when replaced is set. The title is specific and concise.

Full details: Description check

Explanation

The description follows the template: it has a Description section explaining the bug (version None, misleading 'current default' prefix), the rejected alternative (replaced='1.5.1' fails on unknown versions), and the actual change. Types of changes are marked. Tests are described with results and lint status. Fixes # is missing an issue reference, and the Integration/Quick test, docstring, and docs checkboxes are not addressed.

Resolution

Optional: add the linked issue number to 'Fixes #', and state the status of the unchecked items (quick tests, docstrings, docs), or mark them as not applicable.

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

Files selected for processing: 3

  • monai/utils/deprecate_utils.py
  • tests/transforms/test_orientation.py
  • tests/utils/test_deprecated.py
Files skipped from review as they are similar to previous changes: 1

  • monai/utils/deprecate_utils.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.

…tion

Signed-off-by: Ilyass Emssaad <emssaadelias@gmail.com>
@eliem08
eliem08 force-pushed the fix/deprecated-arg-default-message branch from 156bc18 to ea53f77 Compare November 25, 2026 00:13

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