Skip to content

Fix for griffe #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
57 changes: 37 additions & 20 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/docstring_inheritance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion src/docstring_inheritance/class_docstrings_inheritor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions src/docstring_inheritance/griffe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion tests/test_base_inheritor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_google_inheritor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
3 changes: 2 additions & 1 deletion tests/test_numpy_inheritor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
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
from docstring_inheritance.docstring_inheritors.bases.parser import NoSectionFound
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"),
Expand Down
Loading