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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

attributes_doc-0.5.0.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

attributes_doc-0.5.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file attributes_doc-0.5.0.tar.gz.

File metadata

  • Download URL: attributes_doc-0.5.0.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for attributes_doc-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2b29ceb27ccaa85748df19b1c955c7675afca66bc3b1442181d0019b0a79a33a
MD5 5445b96d0debff4868f38947174c005b
BLAKE2b-256 92ff2eab11806e8b0cc7163994617ac78e8548f024b2e1d93d967c6a3cc3a713

See more details on using hashes here.

File details

Details for the file attributes_doc-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: attributes_doc-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for attributes_doc-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 153c62f0e175e8e4697802f201683356abdb83b1bd2e9aa2737f972fec2a13eb
MD5 40d7e61dce0f4b075d6a34a144d99549
BLAKE2b-256 0a7e91130f0b88af2ef58734cae8e645bf64a2e3de87f8b474a1d2a7a9936aac

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 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