-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
bpo-30149: Fix partialmethod without explicit self parameter. #1308
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
Conversation
|
@corona10, thanks for your PR! By analyzing the history of the files in this pull request, we identified @1st1, @larryhastings and @zestyping to be potential reviewers. |
be30903 to
4cc46f8
Compare
|
For reviewers, |
serhiy-storchaka
left a comment
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 @corona10. I didn't expect a fix so fast.
I'm not an expert of the inspect module and left only style notes and questions.
Lib/test/test_inspect.py
Outdated
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.
Follow the style of other tests and move the expected result on the next line.
Lib/test/test_inspect.py
Outdated
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 think it would look clearer if use a local function instead of a lambda.
Are there other tests for partialmethod? If not, it would be nice to add tests for more common partialmethod.
Does this work if there are keyword-only parameters after *args? Does this work if a partialmethod is decorated with classmethod or staticmethod?
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 updated it with adding the case you mentioned!
Lib/inspect.py
Outdated
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'd actually prefer you checking if first_wrapped_param is VAR_POSITIONAL:
sig_params = tuple(sig.parameters.values())
if first_wrapped_param.kind is Parameter.VAR_POSITIONAL:
new_params = sig_params
else:
assert first_wrapped_param is not sig_params[0]
new_params = (first_wrapped_param,) + sig_paramsThere 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.
|
@1st1 |
|
@1st1 @serhiy-storchaka |
Lib/inspect.py
Outdated
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.
Just realized that it's a bit inefficient to construct a new signature object with an unmodified copy of its parameters.
Put a return sig here, and move sig_params = tuple(sig.parameters.values()) to the else block...
Lib/inspect.py
Outdated
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.
... and return sig.replace(parameters=new_params) here ...
Lib/inspect.py
Outdated
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.
... and this return can be then removed.
|
@1st1 |
|
I will improve this diff codecov into 100% today. |
8448b72 to
6de6e6c
Compare
Lib/test/test_inspect.py
Outdated
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.
@serhiy-storchaka @1st1
Codecov complains that they want to add unit test codes for these functions(e.g test_args_only, test_args_kwargs_only ) which are just only for test.
I think that add unit tests code for test code is not reasonable.
What do you think?
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.
Ignore this.
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.
You can put # NOQA like this:
def test_args_only(*args): # NOQA
passThere 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.
@1st1
Thank you for the tip!
I will update it right now!
Lib/inspect.py
Outdated
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.
One last thing: we need a short comment explaining this branch:
# The first argument of the wrapped callable is `*args`,
# as in `partialmethod(lambda *args)`.
return sigThere 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.
That makes sense!
Lib/test/test_inspect.py
Outdated
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.
Two spaces between : and # please (PEP8).
|
@1st1 |
|
@corona10 Could you please add a NEWS entry? |
2cc2379 to
fe3da51
Compare
|
@1st1 Thanks, I updated a NEWS entry. |
Misc/NEWS
Outdated
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.
This is very unusual indentation. Make the entry conforming the style of other entries.
And please use two spaces after a sentence ending period.
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.
Change this to:
- bpo-30149: inspect.signature() now supports callables with
variable-argument parameters wrapped with partialmethod.
Patch by Dong-hee Na.
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.
@serhiy-storchaka Sorry for the mistake. I didn't notice that. I updated it!
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.
@1st1 Thanks!
a91813d to
d28885b
Compare
|
@1st1 @serhiy-storchaka Can you take a look if you are okay? |
|
It's ready, I'll merge it today. |
|
If this is good to @1st1, it is good to me. |
|
@1st1 If you want to merge it. Please ping me. I will rebase it quickly. |
bpo-30149: Fix partialmethod without explicit self parameter.