#NEWLINE# def get_callable_argspec( fn , no_self = False , _is_init = False ) : #NEWLINE# #INDENT# 'Return the argument signature for any callable.\n\n    All pure-Python callables are accepted, including\n    functions, methods, classes, objects with __call__;\n    builtins and other edge cases like functools.partial() objects\n    raise a TypeError.\n\n    ' #NEWLINE# if inspect . isbuiltin ( fn ) : #NEWLINE# #INDENT# raise TypeError ( ( "Can't inspect builtin: %s" % fn ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if inspect . isfunction ( fn ) : #NEWLINE# #INDENT# if ( _is_init and no_self ) : #NEWLINE# #INDENT# spec = compat . inspect_getargspec ( fn ) #NEWLINE# return compat . ArgSpec ( spec . args [ 1 : ] , spec . varargs , spec . keywords , spec . defaults ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return compat . inspect_getargspec ( fn ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if inspect . ismethod ( fn ) : #NEWLINE# #INDENT# if ( no_self and ( _is_init or fn . __self__ ) ) : #NEWLINE# #INDENT# spec = compat . inspect_getargspec ( fn . __func__ ) #NEWLINE# return compat . ArgSpec ( spec . args [ 1 : ] , spec . varargs , spec . keywords , spec . defaults ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return compat . inspect_getargspec ( fn . __func__ ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if inspect . isclass ( fn ) : #NEWLINE# #INDENT# return get_callable_argspec ( fn . __init__ , no_self = no_self , _is_init = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( fn , '__func__' ) : #NEWLINE# #INDENT# return compat . inspect_getargspec ( fn . __func__ ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( fn , '__call__' ) : #NEWLINE# #INDENT# if inspect . ismethod ( fn . __call__ ) : #NEWLINE# #INDENT# return get_callable_argspec ( fn . __call__ , no_self = no_self ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( ( "Can't inspect callable: %s" % fn ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( ( "Can't inspect callable: %s" % fn ) )