Skip to content

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

Merged
iritkatriel merged 6 commits into
python:mainfrom
anton-ryzhov:fix-issue-29858
Nov 10, 2022
Merged

gh-74044: inspect.signature for wrappers around decorated bound methods#736
iritkatriel merged 6 commits into
python:mainfrom
anton-ryzhov:fix-issue-29858

Conversation

@anton-ryzhov

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown

@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
Copy Markdown
Contributor Author

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

Comment thread Lib/inspect.py Outdated
@1st1

1st1 commented Mar 21, 2017

Copy link
Copy Markdown
Member

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

@anton-ryzhov

Copy link
Copy Markdown
Contributor Author

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

@vstinner

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Closing and reopening to trigger tests.

@MaxwellDupre MaxwellDupre left a comment

Copy link
Copy Markdown
Contributor

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
Comment thread Lib/inspect.py Outdated
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@bedevere-bot

Copy link
Copy Markdown

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

Done

Comment thread Misc/NEWS.d/next/Library/2022-11-09-20-48-42.gh-issue-74044.zBj26K.rst Outdated
@iritkatriel
iritkatriel merged commit dbf2faf into python:main Nov 10, 2022
@miss-islington

Copy link
Copy Markdown
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 <anton@ryzhov.me>
@bedevere-bot

Copy link
Copy Markdown

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 <anton@ryzhov.me>
@bedevere-bot

Copy link
Copy Markdown

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