-
-
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
decorator to deprecate positional arguments #6910
Conversation
Are the functions you are considering using this functions that never had keyword arguments before? When I wrote a similar decorator before i had an explicit list of arguments that were allowed to be converted. |
Do you think that you can get it to work with static typing? |
No, I want to consider arguments that have default values. def mean(dim, skipna=None, keep_attrs=None):
pass
@_deprecate_positional_args("v0.1.0")
def mean(dim, *, skipna=None, keep_attrs=None):
pass Or do I missunderstand your question?
I think |
I just realized that there is a bug in the decorator for "keyword-only arguments without a default". I wonder if I should fix this or just disallow this pattern, i.e. the following does currently not work properly: @_deprecate_positional_args("v0.1.0")
def func(a, *, b):
pass but I am not sure how helpful it is. EDIT: It now raises a |
I also just realized, that we made many arguments keyword-only without deprecation (e.g. |
Any objections to merge this as is? |
👍 put it on the meeting agenda for today |
print(f"{args=}") | ||
print(f"{pos_or_kw_args=}") |
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.
are these print statements intentional?
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.
@mathause I think you missed these print statements?
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.
Thanks! Will fix them in a follow up!
@@ -0,0 +1,86 @@ | |||
import inspect |
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.
I would suggest keeping the original copyright notice at the top of the this file.
whats-new.rst
api.rst
Adds a helper function to deprecate positional arguments. IMHO this offers a good trade-off between magic and complexity. (As mentioned this was adapted from scikit-learn).
edit: I suggest to actually deprecate positional arguments in another PR.