This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author petr.viktorin
Recipients petr.viktorin
Date 2015-05-27.15:33:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.


    import inspect
    import functools

    class Foo(object):
        def bar(self, testarg):

    f = Foo()

    def baz(*args):*args)

    assert inspect.signature(baz) == inspect.signature(

The program will fail with an assertion error. Examining inspect.signature(baz) shows:

    >>> print(inspect.signature(baz))
    (self, testarg)
    >>> print(inspect.signature(

Looking at the code in

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

inspect._signature_is_functionlike( returns True, causing Signature.from_function to be called.  Unlike the direct bound method case, this includes the bound method's "self" argument.
Date User Action Args
2015-05-27 15:33:36petr.viktorinsetrecipients: + petr.viktorin
2015-05-27 15:33:36petr.viktorinsetmessageid: <>
2015-05-27 15:33:36petr.viktorinlinkissue24298 messages
2015-05-27 15:33:36petr.viktorincreate