inherit-docstring


Nameinherit-docstring JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/rcmdnk/inherit-docstring
SummaryA python decorator to inherit docstring.
upload_time2023-11-08 18:10:36
maintainer
docs_urlNone
authorrcmdnk
requires_python>=3.9,<4.0
licenseApache-2.0
keywords docstring inherit decorator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # inherit-docstring

[![test](https://github.com/rcmdnk/inherit-docstring/actions/workflows/test.yml/badge.svg)](https://github.com/rcmdnk/inherit-docstring/actions/workflows/test.yml)
[![test coverage](https://img.shields.io/badge/coverage-check%20here-blue.svg)](https://github.com/rcmdnk/inherit-docstring/tree/coverage)

A python decorator to inherit docstring.

Easily inherit docstrings from parent classes with `@inherit_docstring` decorator, designed specifically for [the NumPy docstring style](https://numpydoc.readthedocs.io/en/latest/format.html).

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
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rcmdnk/inherit-docstring",
    "name": "inherit-docstring",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "docstring,inherit,decorator",
    "author": "rcmdnk",
    "author_email": "rcmdnk@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/de/67/2bfd7f8b8c387d02c78d7faea03a2f2e7d81726d30f319b669f45dbdac81/inherit_docstring-0.1.2.tar.gz",
    "platform": null,
    "description": "# inherit-docstring\n\n[![test](https://github.com/rcmdnk/inherit-docstring/actions/workflows/test.yml/badge.svg)](https://github.com/rcmdnk/inherit-docstring/actions/workflows/test.yml)\n[![test coverage](https://img.shields.io/badge/coverage-check%20here-blue.svg)](https://github.com/rcmdnk/inherit-docstring/tree/coverage)\n\nA python decorator to inherit docstring.\n\nEasily inherit docstrings from parent classes with `@inherit_docstring` decorator, designed specifically for [the NumPy docstring style](https://numpydoc.readthedocs.io/en/latest/format.html).\n\nUse inherit-docstring to streamline your documentation process, ensuring consistency and reducing redundancy!\n\n## Features\n\n- Automatic Inheritance: Just add the `@inherit_docstring` decorator, and the child class will seamlessly inherit the parent's class and function docstrings.\n- Structured Sections: Docstrings are broken into sections like `Attributes`, `Notes`, etc. Each section is denoted by its title followed by `---`.\n- Header Section: An exclusive `Header` section is introduced for the starting portion of the docstring without a specific title.\n- Parameter Sections: Certain sections are treated as parameter sections where the content is interpreted as parameter explanations. They include:\n  - Attributes\n  - Parameters\n  - Returns\n  - Yields\n  - Receives\n  - Raises\n  - Warns\n  - Warnings\n- Deprecated sections: Sections starting with `.. deprecated:: x.y.z`, is parsed as deprecated sections.\n\n## Behavior\n\n- If a child class function lacks a docstring, it inherits the parent's docstring verbatim.\n- For functions where both parent and child have docstrings:\n  - Section-wise Merge: Docstrings are combined on a section-by-section basis.\n  - Parameter-wise Merge: Within parameter sections, docstrings are combined parameter by parameter.\n  - Child Priority: When both parent and child provide docstrings for the same function or parameter, the child's version is prioritized.\n\n## Requirement\n\n- Python >=3.9\n- Poetry (For development)\n\n## Installation\n\nBy pip:\n\n```\n$ pip3 install inherit-docstring\n```\n\n## Usage\n\nAdd `inherit_docstring` decorator to the inherited class:\n\n```\nfrom inherit_docstring import inherit_docstring\n\nclass Parent:\n    \"\"\"Parent class.\n\n    This is an explanation.\n\n    Attributes\n    ----------\n    name: str\n        The name of\n        the parent.\n    age:\n        The age. w/o type.\n\n    Notes\n    -----\n    This is parent's note.\n    \"\"\"\n\n    name: str = 'parent'\n    age: int = 40\n\n    def func1(self, param1: int, param2: int) -> int:\n        \"\"\"Parent's func1.\n\n        Parameters\n        ----------\n        param1: int\n            First input.\n        param2: int\n            Second input.\n\n        Returns\n        -------\n        ret: int\n            param1 + param2\n        \"\"\"\n\n        return param1 + param2\n\n    def func2(self) -> None:\n        \"\"\"Parent's func2.\n\n        Returns\n        -------\n        ret: str\n            something\n        \"\"\"\n\n        return 'Something'\n\n@inherit_docstring\nclass Child(Parent):\n    \"\"\"Child class.\n\n    Attributes\n    ----------\n    sex: str\n        Additional attributes.\n        girl or boy.\n    \"\"\"\n\n    sex: str = \"boy\"\n\n    def func1(self, param1: int, param2: int) -> int:\n        \"\"\"Child's func1.\n\n        Returns\n        -------\n        ret: int\n            param1 - param2\n        \"\"\"\n\n        return param1 - param2\n```\n\nChild class' help will be:\n\n```\nclass Child(Parent)\n |  Child class.\n |\n |  Attributes\n |  ----------\n |  name: str\n |      The name of\n |      the parent.\n |  age:\n |      The age. w/o type.\n |  sex: str\n |      Additional attributes.\n |      girl or boy.\n |\n |  Notes\n |  -----\n |  This is parent's note.\n |\n |  Method resolution order:\n |      Child\n |      Parent\n |      builtins.object\n |\n |  Methods defined here:\n |\n |  func1(self, param1: int, param2: int) -> int\n |      Child's func1.\n |\n |      Parameters\n |      ----------\n |      param1: int\n |          First input.\n |      param2: int\n |          Second input.\n |\n |      Returns\n |      -------\n |      ret: int\n |          param1 - param2\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A python decorator to inherit docstring.",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/rcmdnk/inherit-docstring",
        "Repository": "https://github.com/rcmdnk/inherit-docstring"
    },
    "split_keywords": [
        "docstring",
        "inherit",
        "decorator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "604a7fb16e24862b92b3581d790c4ff7eeb12f7d0f6a9466e28ac5c24667eeb5",
                "md5": "56e323798dec0538b92c5cc0efb465be",
                "sha256": "3d93c2a1753969438ef5d17c4abc31baab0ac9cfd182108e335b40bf0e72c1ae"
            },
            "downloads": -1,
            "filename": "inherit_docstring-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "56e323798dec0538b92c5cc0efb465be",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 8978,
            "upload_time": "2023-11-08T18:10:34",
            "upload_time_iso_8601": "2023-11-08T18:10:34.447201Z",
            "url": "https://files.pythonhosted.org/packages/60/4a/7fb16e24862b92b3581d790c4ff7eeb12f7d0f6a9466e28ac5c24667eeb5/inherit_docstring-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "de672bfd7f8b8c387d02c78d7faea03a2f2e7d81726d30f319b669f45dbdac81",
                "md5": "8313dcce70d5b6ccca27bcd75bc1add1",
                "sha256": "931990f644ed093c16b14b4149bf5827cf5e36c97ebae6f5b5f8072a1910a39c"
            },
            "downloads": -1,
            "filename": "inherit_docstring-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "8313dcce70d5b6ccca27bcd75bc1add1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 8741,
            "upload_time": "2023-11-08T18:10:36",
            "upload_time_iso_8601": "2023-11-08T18:10:36.376158Z",
            "url": "https://files.pythonhosted.org/packages/de/67/2bfd7f8b8c387d02c78d7faea03a2f2e7d81726d30f319b669f45dbdac81/inherit_docstring-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-08 18:10:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rcmdnk",
    "github_project": "inherit-docstring",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "inherit-docstring"
}
        
Elapsed time: 0.25121s