Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine DECHAUME committed Jan 13, 2023
2 parents bc5f943 + 0850550 commit e4d341e
Show file tree
Hide file tree
Showing 21 changed files with 659 additions and 384 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/.tox
/.coverage
/htmlcov
/coverage.xml
/build
25 changes: 14 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: LICENSES/headers
exclude: ^LICENSES/headers
- id: check-added-large-files
- id: check-toml
- id: destroyed-symlinks
- id: check-symlinks

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/PyCQA/autoflake
rev: v1.7.7
rev: v2.0.0
hooks:
- id: autoflake
args: [
Expand All @@ -40,10 +40,10 @@ repos:
]

- repo: https://github.com/myint/docformatter
rev: v1.5.0
rev: v1.5.1
hooks:
- id: docformatter
exclude: ^tests/.*$
exclude: ^tests/
args: [
--in-place,
--wrap-summaries,
Expand All @@ -53,30 +53,33 @@ repos:
]

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==22.9.23
- flake8-bugbear==22.12.6
- flake8-docstrings==1.6.0
- flake8-print==5.0.0
- pep8-naming==0.13.2
- pep8-naming==0.13.3

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
exclude: ^(tests/|setup\.py)
args:
- --strict

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.1
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2022-11
### Added
- Support class docstrings with `__init__` signature description.
### Changed
- Some performance improvements.
### Fixed
- Meta-classes API no longer leaks into the classes they create.

## [1.0.1] - 2022-11
### Added
- Support for Python 3.11.

## [1.0.0] - 2021-11
### Changed
- Metaclasses naming.
Expand Down
161 changes: 83 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ such that its derived classes fully or partly inherit the docstrings.
- Handle docstrings for functions, classes, methods, class methods, static methods, properties.
- Handle docstrings for classes with multiple or multi-level inheritance.
- Docstring sections are inherited individually,
like methods for a classes.
like methods.
- For docstring sections documenting signatures,
the signature arguments are inherited individually.
- Minimum performance cost: the inheritance is performed at import time,
Expand Down Expand Up @@ -67,51 +67,57 @@ The docstring inheritance is performed for the docstrings of the:
- staticmethods
- properties

Use the `NumpyDocstringInheritanceMeta` metaclass to inherit docstrings in numpy format.
Use the `NumpyDocstringInheritanceMeta` metaclass to inherit docstrings in numpy format
if `__init__` method is documented in its own docstring.
Otherwise, if `__init__` method is documented in the class docstring,
use the `NumpyDocstringInheritanceInitMeta` metaclass.

Use the `GoogleDocstringInheritanceMeta` metaclass to inherit docstrings in google format.
if `__init__` method is documented in its own docstring.
Otherwise, if `__init__` method is documented in the class docstring,
use the `GoogleDocstringInheritanceInitMeta` metaclass.

```python
from docstring_inheritance import NumpyDocstringInheritanceMeta


class Parent(metaclass=NumpyDocstringInheritanceMeta):
def meth(self, x, y=None):
"""Parent summary.
def meth(self, x, y=None):
"""Parent summary.
Parameters
----------
x:
Description for x.
y:
Description for y.
Parameters
----------
x:
Description for x.
y:
Description for y.
Notes
-----
Parent notes.
"""
Notes
-----
Parent notes.
"""


class Child(Parent):
def meth(self, x, z):
"""
Parameters
----------
z:
Description for z.
def meth(self, x, z):
"""
Parameters
----------
z:
Description for z.
Returns
-------
Something.
Returns
-------
Something.
Notes
-----
Child notes.
"""
Notes
-----
Child notes.
"""


# The inherited docstring is
Child.meth.__doc__ = """Parent summary.
Child.meth.__doc__ == """Parent summary.
Parameters
----------
Expand Down Expand Up @@ -144,35 +150,34 @@ from docstring_inheritance import inherit_google_docstring


def parent():
"""Parent summary.
"""Parent summary.
Args:
x: Description for x.
y: Description for y.
Args:
x: Description for x.
y: Description for y.
Notes:
Parent notes.
"""
Notes:
Parent notes.
"""


def child():
"""
Args:
z: Description for z.
"""
Args:
z: Description for z.
Returns:
Something.
Returns:
Something.
Notes:
Child notes.
"""
Notes:
Child notes.
"""


inherit_google_docstring(parent.__doc__, child)


# The inherited docstring is
child.__doc__ = """Parent summary.
child.__doc__ == """Parent summary.
Args:
x: Description for x.
Expand Down Expand Up @@ -236,29 +241,29 @@ from docstring_inheritance import NumpyDocstringInheritanceMeta


class Parent(metaclass=NumpyDocstringInheritanceMeta):
"""
Attributes
----------
x:
Description for x
y:
Description for y
"""
"""
Attributes
----------
x:
Description for x
y:
Description for y
"""


class Child(Parent):
"""
Attributes
----------
y:
Overridden description for y
z:
Description for z
"""
"""
Attributes
----------
y:
Overridden description for y
z:
Description for z
"""


# The inherited docstring is
Child.__doc__ = """
Child.__doc__ == """
Attributes
----------
x:
Expand Down Expand Up @@ -291,26 +296,26 @@ from docstring_inheritance import GoogleDocstringInheritanceMeta


class Parent(metaclass=GoogleDocstringInheritanceMeta):
def meth(self, w, x, y):
"""
Args:
w: Description for w
x: Description for x
y: Description for y
"""
def meth(self, w, x, y):
"""
Args:
w: Description for w
x: Description for x
y: Description for y
"""


class Child(Parent):
def meth(self, w, y, z):
"""
Args:
z: Description for z
y: Overridden description for y
"""
def meth(self, w, y, z):
"""
Args:
z: Description for z
y: Overridden description for y
"""


# The inherited docstring is
Child.meth.__doc__ = """
Child.meth.__doc__ == """
Args:
w: Description for w
y: Overridden description for y
Expand All @@ -336,11 +341,11 @@ from docstring_inheritance import NumpyDocstringInheritanceMeta


class Meta(abc.ABCMeta, NumpyDocstringInheritanceMeta):
pass
pass


class Parent(metaclass=Meta):
pass
pass
```
# Similar projects

Expand Down
Loading

0 comments on commit e4d341e

Please sign in to comment.