-
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 #5738
Utility function to warn changes in default arguments #5738
Conversation
Signed-off-by: Felix Schnabel <[email protected]>
I still need to write some tests and probably update the documentation but here is the first draft. |
…to `replaced` Signed-off-by: Felix Schnabel <[email protected]>
Signed-off-by: Felix Schnabel <[email protected]>
I looked at this example: from monai.utils import deprecated_arg_default
@deprecated_arg_default(name="b", old_default="e", new_default="d", since="0.8.0", version_val="1.0.0")
def foo(a, b="e"):
return a, b
print(foo(1)) this correctly shows that argument But for the following example, would be great to also provide a forecast for the users, "the default value of argument from monai.utils import deprecated_arg_default
@deprecated_arg_default(name="b", old_default="e", new_default="d", since="1.2.0", version_val="1.0.0")
def foo(a, b="e"):
return a, b
print(foo(1)) |
There are two version constraints: |
ok, |
i mean |
Signed-off-by: Felix Schnabel <[email protected]>
a55a8a0
to
41c9b5f
Compare
@wyli Do you want me to remove the second parameter? Then we just have |
/build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, this looks good, I'll merge if all tests work fine.
Fixes #5653.
Description
A new utility decorator that enables us to warn users of a changing default argument.
Current implementation does the following:
{name}
has been deprecated since version{since}
from{old_default}
to{new_default}
. It will be changed in version{replaced}
."{name}
was changed in version{changed}
from{old_default}
to{new_default}
."old_default
, so you can even use this in scenarios where the default is actuallyNone
but set later in the function. This also enables us to setold_default
to any string if the default is e.g. not printable.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 fornew_default
can be set, giving the same advantages as for theold_default
.Types of changes
./runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.