def signature(obj):
 if (not callable(obj)):
  raise TypeError('{0!r} is not a callable object'.format(obj))
 if isinstance(obj, types.MethodType):
  sig = signature(obj.__func__)
  if (obj.__self__ is None):
   if sig.parameters:
    first = sig.parameters.values()[0].replace(kind=_POSITIONAL_ONLY)
    return sig.replace(parameters=((first,) + tuple(sig.parameters.values())[1:]))
   else:
    return sig
  else:
   return sig.replace(parameters=tuple(sig.parameters.values())[1:])
 try:
  sig = obj.__signature__
 except AttributeError:
  pass
 else:
  if (sig is not None):
   return sig
 try:
  wrapped = obj.__wrapped__
 except AttributeError:
  pass
 else:
  return signature(wrapped)
 if isinstance(obj, types.FunctionType):
  return Signature.from_function(obj)
 if isinstance(obj, functools.partial):
  sig = signature(obj.func)
  new_params = OrderedDict(sig.parameters.items())
  partial_args = (obj.args or ())
  partial_keywords = (obj.keywords or {})
  try:
   ba = sig.bind_partial(*partial_args, **partial_keywords)
  except TypeError as ex:
   msg = 'partial object {0!r} has incorrect arguments'.format(obj)
   raise ValueError(msg)
  for (arg_name, arg_value) in ba.arguments.items():
   param = new_params[arg_name]
   if (arg_name in partial_keywords):
    new_params[arg_name] = param.replace(default=arg_value, _partial_kwarg=True)
   elif ((param.kind not in (_VAR_KEYWORD, _VAR_POSITIONAL)) and (not param._partial_kwarg)):
    new_params.pop(arg_name)
  return sig.replace(parameters=new_params.values())
 sig = None
 if isinstance(obj, type):
  call = _get_user_defined_method(type(obj), '__call__')
  if (call is not None):
   sig = signature(call)
  else:
   new = _get_user_defined_method(obj, '__new__')
   if (new is not None):
    sig = signature(new)
   else:
    init = _get_user_defined_method(obj, '__init__')
    if (init is not None):
     sig = signature(init)
 elif (not isinstance(obj, _NonUserDefinedCallables)):
  call = _get_user_defined_method(type(obj), '__call__', 'im_func')
  if (call is not None):
   sig = signature(call)
 if (sig is not None):
  return sig.replace(parameters=tuple(sig.parameters.values())[1:])
 if isinstance(obj, types.BuiltinFunctionType):
  msg = 'no signature found for builtin function {0!r}'.format(obj)
  raise ValueError(msg)
 raise ValueError('callable {0!r} is not supported by signature'.format(obj))

def signature ( obj ) : if ( not callable ( obj ) ) : raise TypeError ( '{0!r} is not a callable object' . format ( obj ) ) if isinstance ( obj , types . MethodType ) : sig = signature ( obj . __func__ ) if ( obj . __self__ is None ) : if sig . parameters : first = sig . parameters . values ( ) [ 0 ] . replace ( kind = _POSITIONAL_ONLY ) return sig . replace ( parameters = ( ( first , ) + tuple ( sig . parameters . values ( ) ) [ 1 : ] ) ) else : return sig else : return sig . replace ( parameters = tuple ( sig . parameters . values ( ) ) [ 1 : ] ) try : sig = obj . __signature__ except AttributeError : pass else : if ( sig is not None ) : return sig try : wrapped = obj . __wrapped__ except AttributeError : pass else : return signature ( wrapped ) if isinstance ( obj , types . FunctionType ) : return Signature . from_function ( obj ) if isinstance ( obj , functools . partial ) : sig = signature ( obj . func ) new_params = OrderedDict ( sig . parameters . items ( ) ) partial_args = ( obj . args or ( ) ) partial_keywords = ( obj . keywords or { } ) try : ba = sig . bind_partial ( * partial_args , ** partial_keywords ) except TypeError as ex : msg = 'partial object {0!r} has incorrect arguments' . format ( obj ) raise ValueError ( msg ) for ( arg_name , arg_value ) in ba . arguments . items ( ) : param = new_params [ arg_name ] if ( arg_name in partial_keywords ) : new_params [ arg_name ] = param . replace ( default = arg_value , _partial_kwarg = True ) elif ( ( param . kind not in ( _VAR_KEYWORD , _VAR_POSITIONAL ) ) and ( not param . _partial_kwarg ) ) : new_params . pop ( arg_name ) return sig . replace ( parameters = new_params . values ( ) ) sig = None if isinstance ( obj , type ) : call = _get_user_defined_method ( type ( obj ) , '__call__' ) if ( call is not None ) : sig = signature ( call ) else : new = _get_user_defined_method ( obj , '__new__' ) if ( new is not None ) : sig = signature ( new ) else : init = _get_user_defined_method ( obj , '__init__' ) if ( init is not None ) : sig = signature ( init ) elif ( not isinstance ( obj , _NonUserDefinedCallables ) ) : call = _get_user_defined_method ( type ( obj ) , '__call__' , 'im_func' ) if ( call is not None ) : sig = signature ( call ) if ( sig is not None ) : return sig . replace ( parameters = tuple ( sig . parameters . values ( ) ) [ 1 : ] ) if isinstance ( obj , types . BuiltinFunctionType ) : msg = 'no signature found for builtin function {0!r}' . format ( obj ) raise ValueError ( msg ) raise ValueError ( 'callable {0!r} is not supported by signature' . format ( obj ) )
generates a signature .