diff --git a/src/griffe/docstrings/google.py b/src/griffe/docstrings/google.py index 05b1b7ac..35c1a679 100644 --- a/src/griffe/docstrings/google.py +++ b/src/griffe/docstrings/google.py @@ -206,13 +206,14 @@ def _read_parameters( # noqa: WPS231 if annotation is None: _warn(docstring, line_number, f"No type or annotation for parameter '{name}'") - if warn_unknown_params and docstring.parent is not None: - if name not in docstring.parent.parameters: # type: ignore[attr-defined] - _warn( - docstring, - line_number, - f"Parameter '{name}' does not appear in the parent signature", - ) + if warn_unknown_params: + with suppress(AttributeError): # for parameters sections in non-function docstrings + if name not in docstring.parent.parameters: # type: ignore[union-attr] + _warn( + docstring, + line_number, + f"Parameter '{name}' does not appear in the parent signature", + ) parameters.append(DocstringParameter(name=name, value=default, annotation=annotation, description=description)) diff --git a/tests/test_docstrings/test_google.py b/tests/test_docstrings/test_google.py index f3d16d54..9c8a961c 100644 --- a/tests/test_docstrings/test_google.py +++ b/tests/test_docstrings/test_google.py @@ -753,6 +753,22 @@ def test_never_warn_about_unknown_other_parameters(parse_google): assert not warnings +def test_unknown_params_scan_doesnt_crash_on_non_function_docstrings(parse_google): + """Never warn about unknown parameters in "Other parameters" sections. + + Parameters: + parse_google: Fixture parser. + """ + docstring = """ + Parameters: + this (str): This. + that (str): That. + """ + + _, warnings = parse_google(docstring, parent=Class("c")) + assert not warnings + + # TODO: possible feature # def test_missing_parameter(parse_google): # """Warn on missing parameter in docstring.