def format_doc(docstring, *args, **kwargs):
 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

def format_doc ( docstring , * args , ** kwargs ) : 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
replaces the docstring of the decorated object and then formats it .