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.
pip install attributes-docVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade to Python 3.8+ or use `attributes-doc<0.4.0`.
Access attribute docstrings using `MyClass.__doc_attribute__`, `MyEnum.VALUE.__doc__`, or `get_doc(Class, 'attribute_name')`.
Understand that the library's scope is focused solely on adding and retrieving docstrings for class attributes and enum members.
Install the package using pip: 'pip install attributes-doc'.
Ensure the correct usage of the module's functions as per the documentation.
Verify the module's structure and use the correct import statement.
Apply the `@attributes_doc` decorator to the class definition to enable attribute docstring support:
```python
from attributes_doc import attributes_doc, get_attributes_doc
@attributes_doc
class MyClass:
FIELD: str = ""
```Attribute docstrings are retrieved using the provided `get_doc` function, not by directly calling the attribute or its `__doc__`.
```python
from attributes_doc import attributes_doc, get_doc
@attributes_doc
class MyClass:
FIELD: str = "The field's documentation."
print(get_doc(MyClass, 'FIELD'))
```