-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
utility function to warn changes in default arguments #5653
Comments
I would like to work on this. I'm not quite sure if we want to add this functionality into |
agreed, please feel free to create a separate decorator for this feature request. |
My current idea how one could implement this decorator is as follows: @deprecated_arg_default("name", old_default="test", new_default="new_name", since="1.1.0", changed="1.2.0")
def test(name: str = "test"):
print(name)
It will print different messages if Two open questions I still have:
|
it looks good to me, there's no need to add end of warning or consider multiple changes. we may consider another simple case of changing the default behaviour but using the same signature: def test(name=None):
_name = "test"
if name is None:
- _name = "old_default"
+ _name = "new_default"
return _name |
Fixes #5653. ### Description A new utility decorator that enables us to warn users of a changing default argument. Current implementation does the following: - If version < since no warning will be printed. - If the default argument is explicitly set by the caller no warning will be printed. - If since <= version < replaced a warning like this will be printed: "Default of argument `{name}` has been deprecated since version `{since}` from `{old_default}` to `{new_default}`. It will be changed in version `{replaced}`." - If replaced <= version a warning like this will be printed: "Default of argument `{name}` was changed in version `{changed}` from `{old_default}` to `{new_default}`." - It doesn't validate the `old_default`, so you can even use this in scenarios where the default is actually `None` but set later in the function. This also enables us to set `old_default` to any string if the default is e.g. not printable. - The only validation that will throw an error is, if the `new_default` == the actual default and version < replaced. Which means, that somebody replaced the value already, before the version was incremented. Apart from that also any value for `new_default` can be set, giving the same advantages as for the `old_default`. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [x] New tests added to cover the changes. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: Felix Schnabel <[email protected]>
Is your feature request related to a problem? Please describe.
MONAI/monai/utils/deprecate_utils.py
Lines 119 to 127 in e8c6247
the
deprecated_arg
can trigger warnings when a deprecating argument is provided by the user,it however doesn't warn when a default value of an argument has been/will be changed.
for example it's currently not possible to warn about these changes:
random_size
defaulting toFalse
in RandSpatialCropd #5652image_only=True
inLoadImaged
#5007The text was updated successfully, but these errors were encountered: