human
Complete the below
def format_doc(docstring, *args, **kwargs):

    ''''Replaces the docstring of the decorated object and then formats it.
    The formatting works like :meth:`str.format` and if the decorated object
    already has a docstring this docstring can be included in the new
    documentation if you use the ``{__doc__}`` placeholder.
    Its primary use is for reusing a *long* docstring in multiple functions
    when it is the same or only slightly different between them.
    Parameters
    docstring : str or object or None
    The docstring that will replace the docstring of the decorated
    object. If it is an object like a function or class it will
    take the docstring of this object. If it is a string it will use the
    string itself. One special case is if the string is ``None`` then
    it will use the decorated functions docstring and formats it.
    args :
    passed to :meth:`str.format`.
    kwargs :
    passed to :meth:`str.format`. If the function has a (not empty)
    docstring the original docstring is added to the kwargs with the
    keyword ``\'__doc__\'``.
    Raises
    ValueError
    If the ``docstring`` (or interpreted docstring if it was ``None``
    or not a string) is empty.
    IndexError, KeyError
    If a placeholder in the (interpreted) ``docstring`` was not filled. see
    :meth:`str.format` for more information.
    Notes
    Using this decorator allows, for example Sphinx, to parse the
    correct docstring.
    Examples
    Replacing the current docstring is very easy::
    >>> from astropy.utils.decorators import format_doc
    >>> @format_doc(\'\'\'Perform num1 + num2\'\'\')
    ... def add(num1, num2):
    ...     return num1+num2
    >>> help(add) # doctest: +SKIP
    Help on function add in module __main__:
    <BLANKLINE>
    add(num1, num2)
    Perform num1 + num2
    sometimes instead of replacing you only want to add to it::
    >>> doc = \'\'\'
    ...       {__doc__}
    ...       Parameters
    ...       num1, num2 : Numbers
    ...       Returns
    ...       result: Number
    >>> @format_doc(doc)
    ... def add(num1,...'''
 What is a the Python program you requested?
assistant
#Here is the Python program you requested.
    def set_docstring(obj):
        if (docstring is None):
            doc = obj.__doc__
            obj.__doc__ = None
        elif isinstance(docstring, six.string_types):
            doc = docstring
        else:
            doc = docstring.__doc__
        if (not doc):
            raise ValueError('docstring    must    be    a    string    or    containing    a    docstring    that    is    not    empty.')
        kwargs['__doc__'] = (obj.__doc__ or '')
        if (six.PY2 and isinstance(obj, type)):
            obj = type(obj.__name__, (obj,), {'__doc__': doc.format(*args, **kwargs), '__module__': obj.__module__})
        else:
            obj.__doc__ = doc.format(*args, **kwargs)
        return obj
    return set_docstring