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.3.0.tar.gz (4.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.3.0-py2.py3-none-any.whl (4.7 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: attributes-doc-0.3.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for attributes-doc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1139b59601b4d71b90fa7681007160a048885e6d3c7c728ff26bc2cb46621d6a
MD5 cdd05b0b1ade3e2a36747675558a625d
BLAKE2b-256 008da09d0bee95f04ffff28154f6256eebf14f39ace2eee1cd07607170b7dc4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for attributes_doc-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bba25a1b3676f0d843b0e130d6fe1cb126cea940706b0821309733f8785631b2
MD5 9936b7c5ad2409d3f865ae41de99d61e
BLAKE2b-256 efc2a5a5d2f841f021de9a76f67ab6addb5ad62aa31db3aaa89f509af17bbb9e

See more details on using hashes here.

Supported by

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