Is there a way to get function parameter names, including bound-methods excluding `self`?
Question: I can use `inspect.getargspec` to get the parameter names of any function,
including bound methods:

    
    
    >>> import inspect
    >>> class C(object):
    ...     def f(self, a, b):
    ...             pass
    ...
    >>> c = C()
    >>> inspect.getargspec(c.f)
    ArgSpec(args=['self', 'a', 'b'], varargs=None, keywords=None, defaults=None)
    >>>
    

However, `getargspec` includes `self` in the argument list.

Is there a universal way to get the parameter list of any function (and
preferably, any callable at all), excluding `self` if it's a method?

EDIT: Please note, I would like a solution which would on both Python 2 and 3.


Answer: [`inspect.signature`](https://docs.python.org/3/library/inspect.html#inspect.Signature)
excludes the first argument of methods:

    
    
    >>> from inspect import signature
    >>> list(signature(c.f).parameters)
    ['a', 'b']
    

You could also delete the first element of `args` manually:

    
    
    from inspect import ismethod, getargspec
    
    def exclude_self(func):
        args = getargspec(func)
        if ismethod(func):
            args[0].pop(0)
        return args
    
    exclude_self(c.f) # ArgSpec(args=['a', 'b'], ...)
    

