human
Complete this python program:
def formatargspec(function, args, varargs=None, varkw=None, defaults=None, kwonlyargs=(), kwonlydefaults={}, annotations={}):
assistant
#Here is the Python program you requested.

    """Return a string representation of an ``inspect.FullArgSpec`` tuple.
    An enhanced version of ``inspect.formatargspec()`` that handles typing
    annotations better.
    """
    def format_arg_with_annotation(name):
        if (name in annotations):
            return ('%s:    %s' % (name, format_annotation(get_annotation(name))))
        return name
    def get_annotation(name):
        value = annotations[name]
        if isinstance(value, string_types):
            return introspected_hints.get(name, value)
        else:
            return value
    introspected_hints = (typing.get_type_hints(function) if (typing and hasattr(function, '__code__')) else {})
    fd = StringIO()
    fd.write('(')
    formatted = []
    defaults_start = ((len(args) - len(defaults)) if defaults else len(args))
    for (i, arg) in enumerate(args):
        arg_fd = StringIO()
        if isinstance(arg, list):
            arg_fd.write('(')
            arg_fd.write(format_arg_with_annotation(arg[0]))
            for param in arg[1:]:
                arg_fd.write(',    ')
                arg_fd.write(format_arg_with_annotation(param))
            arg_fd.write(')')
        else:
            arg_fd.write(format_arg_with_annotation(arg))
            if (defaults and (i >= defaults_start)):
                arg_fd.write(('    =    ' if (arg in annotations) else '='))
                arg_fd.write(object_description(defaults[(i - defaults_start)]))
        formatted.append(arg_fd.getvalue())
    if varargs:
        formatted.append(('*' + format_arg_with_annotation(varargs)))
    if kwonlyargs:
        if (not varargs):
            formatted.append('*')
        for kwarg in kwonlyargs:
            arg_fd = StringIO()
            arg_fd.write(format_arg_with_annotation(kwarg))
            if (kwonlydefaults and (kwarg in kwonlydefaults)):
                arg_fd.write(('    =    ' if (kwarg in annotations) else '='))
                arg_fd.write(object_description(kwonlydefaults[kwarg]))
            formatted.append(arg_fd.getvalue())
    if varkw:
        formatted.append(('**' + format_arg_with_annotation(varkw)))
    fd.write(',    '.join(formatted))
    fd.write(')')
    if ('return' in annotations):
       ...