Skip to main content

inherit-docstring

test test coverage

A python decorator to inherit docstring.

Easily inherit docstrings from parent classes with @inherit_docstring decorator, designed specifically for the NumPy docstring style.

Use inherit-docstring to streamline your documentation process, ensuring consistency and reducing redundancy!

Features

  • Automatic Inheritance: Just add the @inherit_docstring decorator, and the child class will seamlessly inherit the parent's class and function docstrings.
  • Structured Sections: Docstrings are broken into sections like Attributes, Notes, etc. Each section is denoted by its title followed by ---.
  • Header Section: An exclusive Header section is introduced for the starting portion of the docstring without a specific title.
  • Parameter Sections: Certain sections are treated as parameter sections where the content is interpreted as parameter explanations. They include:
    • Attributes
    • Parameters
    • Returns
    • Yields
    • Receives
    • Raises
    • Warns
    • Warnings
  • Deprecated sections: Sections starting with .. deprecated:: x.y.z, is parsed as deprecated sections.

Behavior

  • If a child class function lacks a docstring, it inherits the parent's docstring verbatim.
  • For functions where both parent and child have docstrings:
    • Section-wise Merge: Docstrings are combined on a section-by-section basis.
    • Parameter-wise Merge: Within parameter sections, docstrings are combined parameter by parameter.
    • Child Priority: When both parent and child provide docstrings for the same function or parameter, the child's version is prioritized.

Requirement

  • Python >=3.9
  • Poetry (For development)

Installation

By pip:

$ pip3 install inherit-docstring

Usage

Add inherit_docstring decorator to the inherited class:

from inherit_docstring import inherit_docstring

class Parent:
    """Parent class.

    This is an explanation.

    Attributes
    ----------
    name: str
        The name of
        the parent.
    age:
        The age. w/o type.

    Notes
    -----
    This is parent's note.
    """

    name: str = 'parent'
    age: int = 40

    def func1(self, param1: int, param2: int) -> int:
        """Parent's func1.

        Parameters
        ----------
        param1: int
            First input.
        param2: int
            Second input.

        Returns
        -------
        ret: int
            param1 + param2
        """

        return param1 + param2

    def func2(self) -> None:
        """Parent's func2.

        Returns
        -------
        ret: str
            something
        """

        return 'Something'

@inherit_docstring
class Child(Parent):
    """Child class.

    Attributes
    ----------
    sex: str
        Additional attributes.
        girl or boy.
    """

    sex: str = "boy"

    def func1(self, param1: int, param2: int) -> int:
        """Child's func1.

        Returns
        -------
        ret: int
            param1 - param2
        """

        return param1 - param2

Child class' help will be:

class Child(Parent)
 |  Child class.
 |
 |  Attributes
 |  ----------
 |  name: str
 |      The name of
 |      the parent.
 |  age:
 |      The age. w/o type.
 |  sex: str
 |      Additional attributes.
 |      girl or boy.
 |
 |  Notes
 |  -----
 |  This is parent's note.
 |
 |  Method resolution order:
 |      Child
 |      Parent
 |      builtins.object
 |
 |  Methods defined here:
 |
 |  func1(self, param1: int, param2: int) -> int
 |      Child's func1.
 |
 |      Parameters
 |      ----------
 |      param1: int
 |          First input.
 |      param2: int
 |          Second input.
 |
 |      Returns
 |      -------
 |      ret: int
 |          param1 - param2

Metadata

Release files for inherit-docstring 0.2.1

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

Source distribution (sdist)

Source distribution for inherit-docstring 0.2.1
File Size Uploaded Provenance
inherit_docstring-0.2.1.tar.gz 9.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for inherit-docstring 0.2.1
File Interpreter ABI Platform
inherit_docstring-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / inherit_docstring-0.2.1.tar.gz

Download URL inherit_docstring-0.2.1.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
32ca474f60c369c7ccf7c71f7789df0acbab2bc576719efe9373b9f93f689c53
BLAKE2b-256 checksum
How to use checksums
a318553e516553ebcb70456c75eb9ecb81d6870ffcedff72ff5bd45d9288f8ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / inherit_docstring-0.2.1-py3-none-any.whl

Download URL inherit_docstring-0.2.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3704e449e64f744152a0ce344a08bba95c19213158edc4e7ae3f0422eeb00cd2
BLAKE2b-256 checksum
How to use checksums
4d954a0dc0db81fca3d6fb73b6a8319d468236376d344f5ce55b32562844324d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for inherit-docstring 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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