Attributes Doc

0.4.0 · active · verified Sun Apr 12

attributes-doc is a Python library providing a hacky implementation of PEP 224 for attribute docstrings. It offers decorators (`attributes_doc`, `enum_doc`) to attach docstrings to class attributes and enum values, and functions (`get_attributes_doc`, `get_doc`) to retrieve them at runtime. The current version is 0.4.0, with a release cadence that has seen updates for Python version compatibility and new features like `enum_doc` in recent major versions.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use the `attributes_doc` decorator for regular classes and `enum_doc` for Enum classes. It also shows how to retrieve the attribute docstrings using both the generated `__doc_ATTRNAME__` attribute (for classes) or `__doc__` (for enum values) and the `get_doc` helper function.

from attributes_doc import attributes_doc, enum_doc, get_doc
from enum import Enum

@attributes_doc
class MyClass:
    foo = 1
    """This is the docstring for foo."""

    bar = 'hello'
    """Docstring for bar."""

print(MyClass.__doc_foo__) # Access docstring via a special attribute
print(get_doc(MyClass, 'bar')) # Use get_doc helper

@enum_doc
class MyEnum(Enum):
    VALUE_A = 1
    """Description for value A."""

    VALUE_B = 2
    """Description for value B."""

print(MyEnum.VALUE_A.__doc__) # Access docstring directly on enum value
print(get_doc(MyEnum, 'VALUE_B')) # Use get_doc helper

view raw JSON →