diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2d8471..01857c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -12,12 +12,12 @@ repos: - id: check-symlinks - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.0 + rev: v0.6.3 hooks: - id: ruff - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.0 + rev: v0.6.3 hooks: - id: ruff-format @@ -39,7 +39,7 @@ repos: ] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.8.0 + rev: v1.11.2 hooks: - id: mypy exclude: ^tests|src/docstring_inheritance/griffe\.py$\a diff --git a/.ruff.toml b/.ruff.toml index 72a292d..da2c833 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -9,8 +9,14 @@ task-tags = ["TODO"] ignore = [ # Conflicts with ruff format. "E203", + # D100 Missing docstring in public module. + "D100", + # D100 Missing docstring in public package. + "D104", # Checks for undocumented magic method definitions. "D105", + # Missing docstring in `__init__`. + "D107", # Checks for long exception messages that are not defined in the exception class itself. "TRY003", # Avoid unexpected behavior with the formatter. @@ -40,53 +46,64 @@ ignore = [ ] select = [ "A", +# "ANN", + "ASYNC", "B", + "BLE", +# "C", "C4", + "D", +# "DOC", "E", + "EM", "F", +# "FA", +# "FBT", + "FLY", + "FURB", "G", "I", - "Q", - "N", - "T", - "W", - "EM", - "UP", - "PT", -# "ANN", - "FLY", "ISC", + "INP", "LOG", + "Q", + "N", "NPY", +# "PL", +# "PD", + "PT", "PIE", + "PGH", "PTH", + "PYI", + "PERF", "RET", "RSE", "RUF", +# "S", "SIM", +# "SLF", + "SLOT", + "T", "T10", "T20", "TCH", "TRY", + "W", + "UP", "YTT", - "SLOT", - "FURB", - "PERF", - "TRIO", -# "C", -# "D", -# "S", -# "PL", -# "PD", -# "BLE", -# "FBT", ] [lint.isort] force-single-line = true +#required-imports = ["from __future__ import annotations"] [lint.pydocstyle] convention = "google" [lint.per-file-ignores] "tests/*.py" = ["D", "PT009","PT011", "PT027", "PTH"] + +[format] +docstring-code-format = true +docstring-code-line-length = 75 diff --git a/CHANGELOG.md b/CHANGELOG.md index 83e4d74..5145d5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ 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). +## [2.2.1] - 2024-09 +### Fixed +- Compatibility with griffe > 1.0.0. + ## [2.2.0] - 2024-03 ### Added - Extension to support building docs with mkdocs. diff --git a/CREDITS.md b/CREDITS.md index 2f893dd..dd61103 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -25,4 +25,3 @@ - [setuptools](https://setuptools.readthedocs.io/): MIT - [setuptools_scm](https://github.com/pypa/setuptools_scm/): MIT - [tox](https://tox.wiki): MIT -- [twine](https://twine.readthedocs.io): MIT diff --git a/requirements/test.txt b/requirements/test.txt index 9ff73fa..2242e42 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -6,23 +6,23 @@ # covdefaults==2.3.0 # via docstring-inheritance (pyproject.toml) -coverage[toml]==7.4.3 +coverage[toml]==7.6.1 # via # covdefaults # pytest-cov -exceptiongroup==1.2.0 +exceptiongroup==1.2.2 # via pytest iniconfig==2.0.0 # via pytest -packaging==23.2 +packaging==24.1 # via pytest -pluggy==1.4.0 +pluggy==1.5.0 # via pytest -pytest==8.1.0 +pytest==8.3.2 # via # docstring-inheritance (pyproject.toml) # pytest-cov -pytest-cov==4.1.0 +pytest-cov==5.0.0 # via docstring-inheritance (pyproject.toml) tomli==2.0.1 # via diff --git a/src/docstring_inheritance/__init__.py b/src/docstring_inheritance/__init__.py index 6787675..dbecdd7 100644 --- a/src/docstring_inheritance/__init__.py +++ b/src/docstring_inheritance/__init__.py @@ -81,7 +81,7 @@ class GoogleDocstringInheritanceMeta(_BaseDocstringInheritanceMeta): """Metaclass for inheriting docstrings in Google format.""" def __init__( - self, + cls, class_name: str, class_bases: tuple[type], class_dict: dict[str, Any], @@ -99,7 +99,7 @@ class GoogleDocstringInheritanceInitMeta(_BaseDocstringInheritanceMeta): """Metaclass for inheriting docstrings in Google format with init-in-class.""" def __init__( - self, + cls, class_name: str, class_bases: tuple[type], class_dict: dict[str, Any], @@ -117,7 +117,7 @@ class NumpyDocstringInheritanceMeta(_BaseDocstringInheritanceMeta): """Metaclass for inheriting docstrings in Numpy format.""" def __init__( - self, + cls, class_name: str, class_bases: tuple[type], class_dict: dict[str, Any], @@ -135,7 +135,7 @@ class NumpyDocstringInheritanceInitMeta(_BaseDocstringInheritanceMeta): """Metaclass for inheriting docstrings in Numpy format with init-in-class.""" def __init__( - self, + cls, class_name: str, class_bases: tuple[type], class_dict: dict[str, Any], diff --git a/src/docstring_inheritance/class_docstrings_inheritor.py b/src/docstring_inheritance/class_docstrings_inheritor.py index 5ebea3e..9295b30 100644 --- a/src/docstring_inheritance/class_docstrings_inheritor.py +++ b/src/docstring_inheritance/class_docstrings_inheritor.py @@ -61,7 +61,7 @@ def __init__( docstring_inheritor: The docstring inheritor. init_in_class: Whether the ``__init__`` arguments documentation is in the class docstring. - """ + """ # noqa: D205, D212 # Remove the new class itself and the object class from the mro, # object's docstrings have no interest. self.__mro_classes = cls.mro()[1:-1] diff --git a/src/docstring_inheritance/docstring_inheritors/bases/inheritor.py b/src/docstring_inheritance/docstring_inheritors/bases/inheritor.py index 4f63493..9e3a707 100644 --- a/src/docstring_inheritance/docstring_inheritors/bases/inheritor.py +++ b/src/docstring_inheritance/docstring_inheritors/bases/inheritor.py @@ -116,7 +116,7 @@ def inherit( Args: parent_doc: The docstring of the parent. child_func: The child function which docstring inherit from the parent. - """ + """ # noqa: D205, D212 if parent_doc is not None: cls(child_func)._inherit(parent_doc) @@ -150,7 +150,7 @@ def _warn_similar_sections( Args: parent_sections: The parent sections. child_sections: The child sections. - section_path: The hierarchy of section names. + super_section_name: The name of the parent section. """ if self.__similarity_ratio == 0.0: return @@ -187,7 +187,8 @@ def _warn_similar_section( Args: parent_doc: The parent documentation. child_doc: The child documentation. - section_path: The hierarchy of section names. + super_section_name: The name of the parent section. + section_name: The name of the section. """ ratio = difflib.SequenceMatcher(None, parent_doc, child_doc).ratio() if ratio >= self.__similarity_ratio: diff --git a/src/docstring_inheritance/docstring_inheritors/bases/parser.py b/src/docstring_inheritance/docstring_inheritors/bases/parser.py index 289b9fd..3d413b7 100644 --- a/src/docstring_inheritance/docstring_inheritors/bases/parser.py +++ b/src/docstring_inheritance/docstring_inheritors/bases/parser.py @@ -41,7 +41,7 @@ from itertools import pairwise else: # pragma: <3.10 cover # See https://docs.python.org/3/library/itertools.html#itertools.pairwise - def pairwise(iterable): + def pairwise(iterable): # noqa: D103 a, b = tee(iterable) next(b, None) return zip(a, b) diff --git a/src/docstring_inheritance/griffe.py b/src/docstring_inheritance/griffe.py index d58329e..14b4b4c 100644 --- a/src/docstring_inheritance/griffe.py +++ b/src/docstring_inheritance/griffe.py @@ -26,20 +26,22 @@ from typing import ClassVar from typing import Literal +from griffe import Alias from griffe import Attribute from griffe import Class from griffe import Docstring from griffe import Extension +from griffe import Inspector from griffe import Object from griffe import ObjectNode +from griffe import Visitor from griffe import dynamic_import from griffe import get_logger -from griffe.dataclasses import Alias if TYPE_CHECKING: import ast - from griffe.enumerations import Parser + from griffe import Parser _logger = get_logger(__name__) @@ -53,7 +55,14 @@ class DocstringInheritance(Extension): __parser_options: ClassVar[dict[str, Any]] = {} """The docstring parser options.""" - def on_class_members(self, node: ast.AST | ObjectNode, cls: Class) -> None: + def on_class_members( # noqa: D102 + self, + *, + node: ast.AST | ObjectNode, + cls: Class, + agent: Visitor | Inspector, + **kwargs: Any, + ) -> None: if isinstance(node, ObjectNode): # Skip runtime objects, their docstrings are already OK. return diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..f837019 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2021 Antoine DECHAUME +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. diff --git a/tests/test_base_inheritor.py b/tests/test_base_inheritor.py index d214a69..caa48bd 100644 --- a/tests/test_base_inheritor.py +++ b/tests/test_base_inheritor.py @@ -98,7 +98,7 @@ class DummyParser(BaseDocstringParser): } -@pytest.fixture() +@pytest.fixture def patch_class(): """Monkey patch BaseDocstringInheritor with docstring parser constants.""" BaseDocstringInheritor._DOCSTRING_PARSER = DummyParser diff --git a/tests/test_google_inheritor.py b/tests/test_google_inheritor.py index 2b82dd6..b32ab8a 100644 --- a/tests/test_google_inheritor.py +++ b/tests/test_google_inheritor.py @@ -20,13 +20,14 @@ from __future__ import annotations import pytest -from test_base_parser import _test_parse_sections from docstring_inheritance.docstring_inheritors.bases import SUMMARY_SECTION_NAME from docstring_inheritance.docstring_inheritors.bases.parser import NoSectionFound from docstring_inheritance.docstring_inheritors.google import DocstringParser from docstring_inheritance.docstring_inheritors.google import DocstringRenderer +from .test_base_parser import _test_parse_sections + @pytest.mark.parametrize( ("unindented_docstring", "expected_sections"), diff --git a/tests/test_numpy_inheritor.py b/tests/test_numpy_inheritor.py index 2d1b408..3f464e3 100644 --- a/tests/test_numpy_inheritor.py +++ b/tests/test_numpy_inheritor.py @@ -20,7 +20,6 @@ from __future__ import annotations import pytest -from test_base_parser import _test_parse_sections from docstring_inheritance import NumpyDocstringInheritor from docstring_inheritance.docstring_inheritors.bases import SUMMARY_SECTION_NAME @@ -28,6 +27,8 @@ from docstring_inheritance.docstring_inheritors.numpy import DocstringParser from docstring_inheritance.docstring_inheritors.numpy import DocstringRenderer +from .test_base_parser import _test_parse_sections + @pytest.mark.parametrize( ("unindented_docstring", "expected_sections"),