Add arguments of versions to convert_positional_args#6009
Conversation
convert_positional_args
|
@not522 @porink0424 Could you review this PR? |
not522
left a comment
There was a problem hiding this comment.
Thank you for your PR! Could you check my comments?
| deprecated_version: str | None = None, | ||
| removed_version: str | None = None, |
There was a problem hiding this comment.
Let me confirm whether we will make the arguments optional. I recommend it is temporarily optional, and we will make it required on follow-up. How about that?
There was a problem hiding this comment.
I agree with you.
There was a problem hiding this comment.
Although I have no preference, I think it would be better to make the input typings stricter based on LSP.
The reason behind this comes from the fact that looser input typings implicitly assume that the function have a routine where we handle the possible input typings.
Namely, we have the processing for removed_version=None in this case and everywhere this function is called may use removed_version=None, which is a bit annoying to update later.
As we have the guidelines for deprecation, I think it would be better to not have optional for now.
There was a problem hiding this comment.
Btw, is removed_version actually replaced_version?
There was a problem hiding this comment.
Sorry, now I noticed that most of them have not specified version, so we need to make it optional for now, probably.
porink0424
left a comment
There was a problem hiding this comment.
Thanks for your PR, I've left some comments.
|
Thank you for reviews!! Test functionWarning |
optuna/_convert_positional_args.py
Outdated
| positional_arg_names = _get_positional_arg_names(func) | ||
| inferred_kwargs = _infer_kwargs(previous_positional_arg_names, *args) | ||
|
|
||
| if inferred_kwargs and (deprecated_version or removed_version): |
There was a problem hiding this comment.
inferred_kwargs include ordinal positional arguments. So we should check the lengths of them.
| if inferred_kwargs and (deprecated_version or removed_version): | |
| if len(inferred_kwargs) > len(positional_arg_names) and (deprecated_version or removed_version): |
|
Thank you for your update! It's almost OK. How about swap the order of warning messages? For example, the following outputs the versions first, but I think It's better to first output what users should do (i.e., from optuna._convert_positional_args import convert_positional_args
@convert_positional_args(
previous_positional_arg_names=["a", "b", "c", "d"],
deprecated_version="3.0.0",
removed_version="4.0.0",
)
def example_function(*, a: int, b: int, c: int = 3, d: int = 4) -> None:
print(f"a: {a}, b: {b}, c: {c}, d: {d}")
example_function(1, 2) |
|
Thank you for your comments again!! |
|
@HideakiImamura I unassigned @porink0424 since he is busy for a while. Could you assign an additional reviewer? |
nabenabe0928
left a comment
There was a problem hiding this comment.
Thank you for the PR, i left some comments:)
| deprecated_version: str | None = None, | ||
| removed_version: str | None = None, |
There was a problem hiding this comment.
Sorry, now I noticed that most of them have not specified version, so we need to make it optional for now, probably.
optuna/_convert_positional_args.py
Outdated
| if deprecated_version is None and removed_version is None: | ||
| pass | ||
| else: |
There was a problem hiding this comment.
| if deprecated_version is None and removed_version is None: | |
| pass | |
| else: | |
| if deprecated_version is not None or removed_version is not None: |
|
Thank you for review!! |
optuna/_convert_positional_args.py
Outdated
| "Positional arguments {deprecated_positional_arg_names} in {func_name}() " | ||
| "have been deprecated since v{d_ver}. " | ||
| "They will be replaced with the corresponding keyword arguments in v{r_ver}, " | ||
| "so please use keyword specification instead. " |
There was a problem hiding this comment.
| "so please use keyword specification instead. " | |
| "so please use the keyword specification instead. " |
nabenabe0928
left a comment
There was a problem hiding this comment.
Thank you for the changes, almost LGTM!
nabenabe0928
left a comment
There was a problem hiding this comment.
Thank you for the update, LGTM!
Motivation
This PR is from #5485
Description of the changes
I added arguments and warning for
deprecated_versionandremoved_version, referring todeprecated_funcThe format of warning is: