[issue20828] inspect.getargspec() returns wrong answer with datetime.today.__call__()

Yury Selivanov report at bugs.python.org
Sun Mar 2 22:17:12 CET 2014


Yury Selivanov added the comment:

OK, I see.

I'd recommend you to take a look how inspect.signature is implemented in 3.3 or 3.4 (and maybe backport it to python 2 and use the new API).

To quickly fix your code, I'd suggest the following modifications:

_WrapperDescriptor = type(type.__call__)
_MethodWrapper = type(all.__call__)
_ClassMethodWrapper = type(int.__dict__['from_bytes'])

def get_callable_argspec(fn):
    if inspect.isfunction(fn) or inspect.ismethod(fn):
        inspectable = fn
    elif inspect.isclass(fn):
        inspectable = fn.__init__
    elif hasattr(fn, '__call__'):
        inspectable = fn.__call__
    else:
        inspectable = fn
   
    if isinstance(fn, (_WrapperDescriptor, _MethodWrapper, _ClassMethodWrapper)):
        raise ValueError('unsupported callable {!r}'.format(fn))

    try:
        return inspect.getargspec(inspectable)
    except TypeError:
        raise


I'm closing this issue, as there is no real bug or regression in getargspec.

----------
resolution:  -> invalid
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20828>
_______________________________________


More information about the Python-bugs-list mailing list