Skip to content

documented

Python Version wemake-python-styleguide PyPI - License

Templated docstrings for Python classes.

Example

examples/open-the-pod-bay-doors.py

from dataclasses import dataclass

from documented import Documented, DocumentedError


@dataclass
class PodBayDoorsStillClosed(DocumentedError):
    """
    I’m sorry, {self.user_name}.

    I’m afraid I can’t do that.
    """

    user_name: str


class OpenThePodBayDoors(Documented):
    """Open the pod bay doors please, HAL."""


print(OpenThePodBayDoors())
raise PodBayDoorsStillClosed(user_name='Dave')

python

Open the pod bay doors please, HAL.

Traceback (most recent call last):
  File "πŸ“‚/open-the-pod-bay-doors.py", line 22, in <module>
    raise PodBayDoorsStillClosed(user_name='Dave')
PodBayDoorsStillClosed: I’m sorry, Dave.

I’m afraid I can’t do that.

Installation

documented is on PyPI.

pip install documented
poetry add documented
pipenv install documented
pdm add documented
conda install -c conda-forge documented

Flow

graph TD
    docstring("Class πŸ“ <code>docstring</code>") --> dedent("ↀ dedent")
    dedent --> C("✏️ Interpolate<br><code>{self.placeholders}</code>")
    C --> str("<code>__str__()</code>")
    str -- "for<br><code>DocumentedError</code>" --> raise("πŸ’₯ raise")
    str -- "for<br><code>Documented</code>" --> print("πŸ–¨οΈ print | log")
    print --> rich("as Markdown β†’ console<br>with πŸ–₯️ <code>rich</code>")
    raise --> try("πŸ€ try … except")
    raise -- Stacktrace --> print
    try --> print

    style raise stroke:#CC0000
    click dedent "https://docs.python.org/3/library/textwrap.html#textwrap.dedent"
    click C "templating/"
    click rich "compatibility/rich/"
    click str "https://docs.python.org/3/reference/datamodel.html#object.__str__"
    click try "try-except/"
    click docstring "docstring/"

πŸ“¦ Used by

The asterisk below denotes projects which are mine πŸ™‚

iolanta

Linked Data workspace

jeeves

Pythonic alternative to Make

Know more?

βž• Submit an issue!


Let's talk

Bug? Feature request?

βž• Submit an issue!

Anything else?

See my site: yeti.sh


Publications