Skip to main content

attributes-doc

PyPI version PyPI - Python Version Check codecov

Hacky implementation of PEP 224.

Usage

This package provides the following functions:

  • attributes_doc
  • get_attributes_doc
  • enum_doc
  • get_doc

Decorator attributes_doc

This function is a class decorator, and using it on a class will set class attributes called __doc_ATTRNAME__ for each existing attribute.

from attributes_doc import attributes_doc


@attributes_doc
class Foo:
    bar = 1
    """This is the docstring for the bar attribute.

    It will be stored in `Foo.__doc_bar__` and will be accessible at runtime.
    """

    baz = 2
    """This is the docstring for the baz attribute."""


print(Foo.__doc_bar__)
print(getattr(Foo, "__doc_baz__"))

Function get_attributes_doc

This function will return a dictionary with the docstrings for all attributes of a class without setting them.

from attributes_doc import get_attributes_doc


class Goo:
    """This class doesn't use attributes_doc and we don't want to modify it at all."""

    bar = 1
    """This is the docstring for the bar attribute."""
    baz = 2
    """This is the docstring for the baz attribute."""


docs = get_attributes_doc(Goo)
print(docs["bar"])
print(docs["baz"])

Decorator enum_doc

This is also a class decorator, but it is intended for Enum classes. Instead of setting one doc attribute per attribute to the containing class, it will set the __doc__ attribute for each enum value.

from attributes_doc import enum_doc
from enum import Enum


@enum_doc
class Foo(Enum):
    bar = 1
    """This is the docstring for the bar attribute."""
    baz = 2
    """This is the docstring for the baz attribute."""


print(Foo.bar.__doc__)

Function get_doc

This function will return the docstring of an attribute of a class.

from attributes_doc import get_doc

print(get_doc(Foo, "baz"))  # Instead of getattr(Foo, "__doc_baz__") above

Metadata

Release files for attributes-doc 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for attributes-doc 0.5.0
File Size Uploaded
attributes_doc-0.5.0.tar.gz 37.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for attributes-doc 0.5.0
File Interpreter ABI Platform
attributes_doc-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.6 kB

Release files / attributes_doc-0.5.0.tar.gz

Download URL attributes_doc-0.5.0.tar.gz
Size 37.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2b29ceb27ccaa85748df19b1c955c7675afca66bc3b1442181d0019b0a79a33a
BLAKE2b-256 checksum
How to use checksums
92ff2eab11806e8b0cc7163994617ac78e8548f024b2e1d93d967c6a3cc3a713
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / attributes_doc-0.5.0-py3-none-any.whl

Download URL attributes_doc-0.5.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
153c62f0e175e8e4697802f201683356abdb83b1bd2e9aa2737f972fec2a13eb
BLAKE2b-256 checksum
How to use checksums
0a7e91130f0b88af2ef58734cae8e645bf64a2e3de87f8b474a1d2a7a9936aac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page