Repository navigation
Conversation
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>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
vikashg
left a comment
There was a problem hiding this comment.
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.
|
Thanks for the review, and for testing it against the PR head. I checked the two callers ( I've also pushed a follow-up commit adding a test that locks in the new message on the real |
Description
Since #8473 (1.5.1),
OrientationandOrientationdwarn on every construction that doesn't passlabels:The decorator is declared without
since/replaced, sodeprecated_arg_defaultprintsversion None, and the "Current default value of argumentlabels=(('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_replacedis False, the signature default already equalsnew_default, and the decorator raisesValueErrorat import time.This PR changes only the message for a replaced default:
and includes
in version Xwhenreplacedis 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
Tests
test_deprecated_arg_default_replaced_messagechecks the wording with and without a version.tests/utils/test_deprecated.py,tests/transforms/test_orientation.pyandtest_orientationd.py: 99 passed (98 before plus the new test). The 2 pytest errors ontest_orientationd.py(test_resampler_lazycollected as a test, fixtureresamplernot found) also occur on unmodifieddev.black --checkandruff checkpass on the changed files.