Skip to main content

Parse, check and update doc-string documentation

Project description

docsource: Parse, check and update doc-string documentation

docsource parses Python documentation strings (a.k.a. doc-string) for (data) classes and functions.

A doc-string is broken down into the following components:

  • A short description, which is the first block of text in the documentation string, and ends with a double newline or a parameter block.
  • A long description, which is the optional block of text following the short description, and ends with a parameter block.
  • A parameter block of named parameter and description string pairs in ReST-style, each declared with param.
  • A returns declaration, which adds explanation to the return value.
  • A raises declaration, which adds explanation to the exception type raised by the function on error.
class SampleClass:
    def instance_method(self, a: str, b: int | None) -> str:
        """
        Short description of an instance method.

        :param a: Short description for `a`.
        :param b: Short description for `b`.
        :returns: A return value.
        :raise TypeError: A type exception rarely raised.
        :raise ValueError: A value exception rarely raised.
        :raise CustomException: A custom exception.
        """
        return ""

When the doc-string is attached to a data class, it is understood as the documentation string of the class __init__ method.

Compliance

docsource verifies if

  • parameters listed in the function doc-string have corresponding parameters in the function signature,
  • parameters declared in a function signature have corresponding doc-string entries (strict mode only),
  • data-class members listed in the function doc-string have corresponding member variables in the data-class definition,
  • members declared in a data-class have corresponding doc-string entries (strict mode only).

Enumerations

Python's own doc-string mechanism doesn't allow attaching a description to enumeration members. However, documentation toolchains such as Sphinx's autodoc support this with a string literal immediately following the enumeration member value assignment:

@enum.unique
class EnumType(enum.Enum):
    ENABLED = "enabled"
    "Documents the enumeration member `ENABLED`."

    DISABLED = "disabled"
    "Documents the enumeration member `DISABLED`."

docsource can parse source code with Python's ast module to extract these description text strings.

Documentation style

docsource can normalize code documentation by reading source code (with Python's ast), identifying doc-string literals, parsing doc-string text, and producing a standardized doc-string with short description, and ReST-style parameter, return value and exception declarations.

Refer to the source

  • The function parse_type parses a ReST-style doc-string attached to a class or function into doc-string components, encapsulated in the class Docstring.
  • The function parse_text parses raw doc-string text into its components.
  • check_docstring verifies data-class and function doc-string text.
  • enum_labels extracts textual description for enumeration members.
  • update_docstring standardizes doc-string literals in Python source code.

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

docsource-0.1.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

docsource-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file docsource-0.1.0.tar.gz.

File metadata

  • Download URL: docsource-0.1.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for docsource-0.1.0.tar.gz
Algorithm Hash digest
SHA256 adbdc8204924201591e49a930974cf639b598e6c1e41cc3da837857ca183d8be
MD5 50c0ec412a873c7183456132550d2a43
BLAKE2b-256 2d4a9bde6b4e09e8e5dcf7de35e11d89e92c32be3cb229001c2d68b6e8bf9ae9

See more details on using hashes here.

File details

Details for the file docsource-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: docsource-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for docsource-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfb1cecb177a4baadd6b85c88e7140ad1a2056de37f29b0188dc6f5ab9a4e603
MD5 8c4cea4ba29c4cb1d6fa983cdfdf2dfb
BLAKE2b-256 eea6e090addae43be66a48ba0a2afb4d1071a75ba0df06a6162c497e5b62579e

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