Skip to content
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

bpo-29858: inspect.signature for wrappers around decorated bound methods #736

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anton-ryzhov
Copy link

@anton-ryzhov anton-ryzhov commented Mar 20, 2017

http://bugs.python.org/issue29858

If we wrap function with bound method, which is also a wrapper around function, inspect.signature will not do skip_bound_arg.
It will use inspect.unwrap and pass by bound method from outer function to inner one.

Reproduce:

import functools, inspect


def decorator(func):
    @functools.wraps(func)
    def inner(*args):
        return func(*args)
    return inner


class Foo(object):
    @decorator
    def bar(self, testarg):
        pass


f = Foo()
baz = decorator(f.bar)
assert inspect.signature(baz) == inspect.signature(f.bar)

https://bugs.python.org/issue29858

@the-knights-who-say-ni
Copy link

@the-knights-who-say-ni the-knights-who-say-ni commented Mar 20, 2017

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow these steps to rectify the issue:

  1. Sign the PSF contributor agreement. The "bugs.python.org username" requested by the form is the "Login name" field in "Your Details" at b.p.o
  2. Wait at least one US business day and then check the "Contributor form received entry under "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  3. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

@mention-bot
Copy link

@mention-bot mention-bot commented Mar 20, 2017

@anton-ryzhov, 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.

@serhiy-storchaka serhiy-storchaka added type-bug needs backport to 3.5 labels Mar 20, 2017
@serhiy-storchaka serhiy-storchaka requested a review from 1st1 Mar 20, 2017
@anton-ryzhov
Copy link
Author

@anton-ryzhov anton-ryzhov commented Mar 20, 2017

@the-knights-who-say-ni Got "Contributor Form Received"

@@ -2171,7 +2171,8 @@ def _signature_from_callable(obj, *,

# Was this function wrapped by a decorator?
if follow_wrapper_chains:
obj = unwrap(obj, stop=(lambda f: hasattr(f, "__signature__")))
Copy link
Member

@1st1 1st1 Mar 21, 2017

Choose a reason for hiding this comment

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

Need to add a comment here explaining the "or" in unwrap lambda.

Copy link
Author

@anton-ryzhov anton-ryzhov Jan 21, 2019

Choose a reason for hiding this comment

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

If you've missed this change — I've added this in commit below. Should this branch be resolved to continue review of this PR?

@1st1
Copy link
Member

@1st1 1st1 commented Mar 21, 2017

@anton-ryzhov Good catch. The code looks OK, just add a comment explaining why your change works in all cases.

@anton-ryzhov
Copy link
Author

@anton-ryzhov anton-ryzhov commented Mar 23, 2017

@1st1 In case you haven't received notification about last push, I'm notifying about this by the comment.

@vstinner
Copy link
Member

@vstinner vstinner commented Jan 10, 2019

I removed the " needs backport to 3.6" label, the 3.6 branch no longer accept bugfixes (only security fixes are accepted): https://devguide.python.org/#status-of-python-branches

@csabella csabella requested a review from 1st1 Apr 9, 2019
@csabella
Copy link
Contributor

@csabella csabella commented Apr 10, 2019

@1st1, I believe your requested changes have been made and this is ready for another review. Thanks!

@csabella csabella requested review from 1st1 and removed request for 1st1 Nov 16, 2019
@csabella
Copy link
Contributor

@csabella csabella commented Nov 16, 2019

Closing and reopening to trigger tests.

Copy link
Contributor

@MaxwellDupre MaxwellDupre left a comment

Tested as per given test case, result pass.
Module test passed test_inspect.
Noted make failed to build nis module.
Looks ok to me.

@github-actions
Copy link

@github-actions github-actions bot commented Mar 18, 2022

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review CLA signed stale type-bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet