Skip to content

gh-74044: inspect.signature for wrappers around decorated bound methods #736

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

Merged
merged 6 commits into from
Nov 10, 2022

Conversation

anton-ryzhov
Copy link
Contributor

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

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.

Reproducer:

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)

@the-knights-who-say-ni

This comment was marked as outdated.

@mention-bot
Copy link

@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 An unexpected behavior, bug, or error needs backport to 3.5 labels Mar 20, 2017
@serhiy-storchaka serhiy-storchaka requested a review from 1st1 March 20, 2017 09:37
@anton-ryzhov
Copy link
Contributor Author

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

@1st1
Copy link
Member

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
Contributor Author

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

@vstinner
Copy link
Member

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 April 9, 2019 23:59
@csabella
Copy link
Contributor

@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 November 16, 2019 02:03
@csabella
Copy link
Contributor

Closing and reopening to trigger tests.

Copy link
Contributor

@MaxwellDupre MaxwellDupre left a comment

Choose a reason for hiding this comment

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

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

@AlexWaygood AlexWaygood changed the title bpo-29858: inspect.signature for wrappers around decorated bound methods gh-74044: inspect.signature for wrappers around decorated bound methods Nov 9, 2022
Co-authored-by: Irit Katriel <[email protected]>
@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@iritkatriel
Copy link
Member

@anton-ryzhov This needs a news entry.

@iritkatriel iritkatriel added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes and removed stale Stale PR or inactive for long period of time. labels Nov 9, 2022
@anton-ryzhov
Copy link
Contributor Author

Done

@iritkatriel iritkatriel merged commit dbf2faf into python:main Nov 10, 2022
@miss-islington
Copy link
Contributor

Thanks @anton-ryzhov for the PR, and @iritkatriel for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 10, 2022
… methods (pythonGH-736)

(cherry picked from commit dbf2faf)

Co-authored-by: Anton Ryzhov <[email protected]>
@bedevere-bot
Copy link

GH-99328 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Nov 10, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 10, 2022
… methods (pythonGH-736)

(cherry picked from commit dbf2faf)

Co-authored-by: Anton Ryzhov <[email protected]>
@bedevere-bot
Copy link

GH-99329 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Nov 10, 2022
miss-islington added a commit that referenced this pull request Nov 10, 2022
…ds (GH-736)

(cherry picked from commit dbf2faf)

Co-authored-by: Anton Ryzhov <[email protected]>
miss-islington added a commit that referenced this pull request Nov 10, 2022
…ds (GH-736)

(cherry picked from commit dbf2faf)

Co-authored-by: Anton Ryzhov <[email protected]>
ethanfurman pushed a commit to ethanfurman/cpython that referenced this pull request Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.