Description of problem:
When obtaining the signature of a bound method, inspect.signature, by default, omits the "self" argument to the method, since it is already specified in the bound method. However, if you create a wrapper around a bound method with functools.update_wrapper() or @functools.wraps, calling inspect.signature on the wrapper will return a signature which includes the "self" argument.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Enter the following Python sample code
def bar(self, testarg):
f = Foo()
assert inspect.signature(baz) == inspect.signature(f.bar)
2. Run the sample code
The program will fail with an assertion error. Examining inspect.signature(baz) shows:
The assertion should not trip, and inspect.signature(baz) should be the same as inspect.signature(f.bar)
Looking at the code in inspect.py:
The handling of bound methods appears at the top of inspect._signature_internal(). Since baz is not itself a bound method, it doesn't trigger this case. Instead inspect.unwrap is called, returning f.bar.
inspect._signature_is_functionlike(f.bar) returns True, causing Signature.from_function to be called. Unlike the direct bound method case, this includes the bound method's "self" argument.
I've had a look at the upstream cpython hg tree. inspect.py has been rearranged a fair bit, but it looks like the bug is still present there.
I'm looking into getting the right credentials to file the bug in the upstream tracker.
This package has changed ownership in the Fedora Package Database. Reassigning to the new owner of this component.
David, are you still on this? I can forward this upstream if you don't have time to get your credentials.
Sorry, I've been away on holiday the last 2 weeks. I'm back now.
Please do forward this upstream, that would be very helpful.
Reported as http://bugs.python.org/issue24298
Hi, I see this from that link that the bug has now been resolved upstream.
I've checked and the bug is still present in Fedora 22 - any idea on how long this will take to be folded back into Fedora?
It's been resolved, but's not yet released. In Fedora we generally avoid backporting individual patches.
There's no info upstream about 3.4.4 schedule, unfortunately.
Fedora 22 changed to end-of-life (EOL) status on 2016-07-19. Fedora 22 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.
If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
Thank you for reporting this bug and we are sorry it could not be fixed.
Appears to be fixed in Fedora 24.