docutils.py 506 B

12345678910111213
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. def doc_subst(snippets):
  4. """ Substitute format strings in class or function docstring """
  5. def decorator(cls):
  6. # Strip the snippets to avoid trailing new lines and whitespace
  7. stripped_snippets = {
  8. key: snippet.strip() for (key, snippet) in snippets.items()
  9. }
  10. cls.__doc__ = cls.__doc__.format(**stripped_snippets)
  11. return cls
  12. return decorator