Skip to content

Conversation

@corona10
Copy link
Member

bpo-30149: Fix partialmethod without explicit self parameter.

@mention-bot
Copy link

@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.

@corona10 corona10 force-pushed the bpo-30149 branch 2 times, most recently from be30903 to 4cc46f8 Compare April 26, 2017 18:02
@corona10
Copy link
Member Author

corona10 commented Apr 26, 2017

For reviewers,
test_imaplib is commonly failed includes other PR now.
This issue is not related to this PR.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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.

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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_params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1st1
I should read pep-0362 before fixing this. Thanks!

@corona10 corona10 changed the title bpo-30149: Fix partialmethod without explicit self parameter. [WIP] bpo-30149: Fix partialmethod without explicit self parameter. Apr 27, 2017
@corona10
Copy link
Member Author

@1st1
Thank you for reviewing my PR. You approach is much better than I did.
I updated it and soon going to update unit tests which @serhiy-storchaka guided.

@corona10 corona10 changed the title [WIP] bpo-30149: Fix partialmethod without explicit self parameter. bpo-30149: Fix partialmethod without explicit self parameter. Apr 27, 2017
@corona10
Copy link
Member Author

@1st1 @serhiy-storchaka
Updated it, Can you take a look?

Lib/inspect.py Outdated
Copy link
Member

@1st1 1st1 Apr 27, 2017

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
Copy link
Member

@1st1 1st1 Apr 27, 2017

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
Copy link
Member

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.

@corona10
Copy link
Member Author

@1st1
Updated! Please take a look

@corona10
Copy link
Member Author

I will improve this diff codecov into 100% today.

@corona10 corona10 force-pushed the bpo-30149 branch 2 times, most recently from 8448b72 to 6de6e6c Compare April 28, 2017 12:43
Copy link
Member Author

@corona10 corona10 Apr 28, 2017

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this.

Copy link
Member

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
            pass

Copy link
Member Author

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
Copy link
Member

@1st1 1st1 Apr 28, 2017

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 sig

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense!

Copy link
Member

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).

@corona10
Copy link
Member Author

@1st1
Updated and all passed.
PTAL

@1st1
Copy link
Member

1st1 commented May 1, 2017

@corona10 Could you please add a NEWS entry?

@corona10 corona10 force-pushed the bpo-30149 branch 2 times, most recently from 2cc2379 to fe3da51 Compare May 1, 2017 23:37
@corona10
Copy link
Member Author

corona10 commented May 1, 2017

@1st1 Thanks, I updated a NEWS entry.

Misc/NEWS Outdated
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1st1 Thanks!

@corona10 corona10 force-pushed the bpo-30149 branch 3 times, most recently from a91813d to d28885b Compare May 3, 2017 13:56
@corona10
Copy link
Member Author

corona10 commented May 5, 2017

@1st1 @serhiy-storchaka Can you take a look if you are okay?

@1st1
Copy link
Member

1st1 commented May 5, 2017

It's ready, I'll merge it today.

@serhiy-storchaka
Copy link
Member

If this is good to @1st1, it is good to me.

@corona10
Copy link
Member Author

@1st1 If you want to merge it. Please ping me. I will rebase it quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants