Skip to content

Commit a15e782

Browse files
committed
fix: Forward warn_missing_types to Sphinx return section reader
Issue-mkdocstrings-python-337: mkdocstrings/python#337
1 parent 277bfdc commit a15e782

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎packages/griffelib/src/griffe/_internal/docstrings/sphinx.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class SphinxOptions(TypedDict, total=False):
9191

9292
warn_unknown_params: bool
9393
"""Whether to warn about unknown parameters."""
94+
warn_missing_types: bool
95+
"""Whether to warn about missing types or annotations."""
9496
warnings: bool
9597
"""Whether to issue warnings for parsing issues."""
9698

@@ -99,13 +101,15 @@ def parse_sphinx(
99101
docstring: Docstring,
100102
*,
101103
warn_unknown_params: bool = True,
104+
warn_missing_types: bool = True,
102105
warnings: bool = True,
103106
) -> list[DocstringSection]:
104107
"""Parse a Sphinx-style docstring.
105108
106109
Parameters:
107110
docstring: The docstring to parse.
108111
warn_unknown_params: Warn about documented parameters not appearing in the signature.
112+
warn_missing_types: Warn about missing types or annotations.
109113
warnings: Whether to log warnings at all.
110114
111115
Returns:
@@ -115,6 +119,7 @@ def parse_sphinx(
115119

116120
options = {
117121
"warn_unknown_params": warn_unknown_params,
122+
"warn_missing_types": warn_missing_types,
118123
"warnings": warnings,
119124
}
120125

‎packages/griffelib/tests/test_docstrings/test_sphinx.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,3 +1311,16 @@ def test_disabled_warnings(parse_sphinx: ParserType) -> None:
13111311
assert warnings
13121312
_, warnings = parse_sphinx(docstring, warnings=False)
13131313
assert not warnings
1314+
1315+
1316+
def test_disabled_missing_type_warnings(parse_sphinx: ParserType) -> None:
1317+
"""Assert missing type warnings can be disabled.
1318+
1319+
Parameters:
1320+
parse_sphinx: Fixture parser.
1321+
"""
1322+
docstring = ":return: A value."
1323+
_, warnings = parse_sphinx(docstring, warn_missing_types=True)
1324+
assert warnings
1325+
_, warnings = parse_sphinx(docstring, warn_missing_types=False)
1326+
assert not warnings

0 commit comments

Comments
 (0)