Skip to main content

PEP 224 implementation

Project description

attributes-doc

PyPI version PyPI - Python Version Build Status 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

Project details


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.4.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

attributes_doc-0.4.0-py2.py3-none-any.whl (4.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file attributes-doc-0.4.0.tar.gz.

File metadata

  • Download URL: attributes-doc-0.4.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for attributes-doc-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b1576c94a714e9fc2c65c47cf10d0c8e1a5f7c4f5ae7f69006be108d95cbfbfb
MD5 df3ad7a3b3f696804395066300fddacd
BLAKE2b-256 2d8bbcfe09838dfc88474c29aeca781860938b3909e6df47a3d0d70e97ad79c2

See more details on using hashes here.

File details

Details for the file attributes_doc-0.4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for attributes_doc-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4c3007d9e58f3a6cb4b9c614c4d4ce2d92161581f28e594ddd8241cc3a113bdd
MD5 cf1dea9fd7852e00df4a38889ffdb659
BLAKE2b-256 d897c2ca0e0e4c2de15996b5f738964d7ca0b9c8d6e116edb307ad30d5e56a59

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page