def fix_type_error(exc_info, callable, varargs, kwargs):
 if (exc_info is None):
  exc_info = sys.exc_info()
 if ((exc_info[0] != TypeError) or (str(exc_info[1]).find('arguments') == (-1)) or getattr(exc_info[1], '_type_error_fixed', False)):
  return exc_info
 exc_info[1]._type_error_fixed = True
 argspec = inspect.formatargspec(*inspect.getargspec(callable))
 args = ', '.join(map(_short_repr, varargs))
 if (kwargs and args):
  args += ', '
 if kwargs:
  kwargs = sorted(kwargs.keys())
  args += ', '.join((('%s=...' % n) for n in kwargs))
 gotspec = ('(%s)' % args)
 msg = ('%s; got %s, wanted %s' % (exc_info[1], gotspec, argspec))
 exc_info[1].args = (msg,)
 return exc_info

def fix_type_error ( exc_info , callable , varargs , kwargs ) : if ( exc_info is None ) : exc_info = sys . exc_info ( ) if ( ( exc_info [ 0 ] != TypeError ) or ( str ( exc_info [ 1 ] ) . find ( 'arguments' ) == ( - 1 ) ) or getattr ( exc_info [ 1 ] , '_type_error_fixed' , False ) ) : return exc_info exc_info [ 1 ] . _type_error_fixed = True argspec = inspect . formatargspec ( * inspect . getargspec ( callable ) ) args = ', ' . join ( map ( _short_repr , varargs ) ) if ( kwargs and args ) : args += ', ' if kwargs : kwargs = sorted ( kwargs . keys ( ) ) args += ', ' . join ( ( ( '%s=...' % n ) for n in kwargs ) ) gotspec = ( '(%s)' % args ) msg = ( '%s; got %s, wanted %s' % ( exc_info [ 1 ] , gotspec , argspec ) ) exc_info [ 1 ] . args = ( msg , ) return exc_info
given an exception .