bpo-30149: Fix partialmethod without explicit self parameter.#1308
bpo-30149: Fix partialmethod without explicit self parameter.#13081st1 merged 2 commits intopython:masterfrom
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.
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.
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.
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.
I updated it with adding the case you mentioned!
Lib/inspect.py
Outdated
There was a problem hiding this comment.
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_params|
@1st1 |
|
@1st1 @serhiy-storchaka |
Lib/inspect.py
Outdated
There was a problem hiding this comment.
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.
... and return sig.replace(parameters=new_params) here ...
Lib/inspect.py
Outdated
There was a problem hiding this comment.
... 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.
@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.
You can put # NOQA like this:
def test_args_only(*args): # NOQA
passThere was a problem hiding this comment.
@1st1
Thank you for the tip!
I will update it right now!
Lib/inspect.py
Outdated
There was a problem hiding this comment.
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 sig
Lib/test/test_inspect.py
Outdated
There was a problem hiding this comment.
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.
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.
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.
@serhiy-storchaka Sorry for the mistake. I didn't notice that. I updated it!
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.