Skip to content

Commit 2b0a123

Browse files
committed
raises exception
1 parent 093ffd5 commit 2b0a123

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

PyDocSmith/google.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,26 @@ def parse(self, text: str) -> Docstring:
326326
part = chunk[start:end].strip("\n")
327327
ret.meta.append(self._build_meta(part, title))
328328
ret.meta = [m for m in ret.meta if m]
329-
return ret
329+
return remove_non_required_exceptions(ret)
330+
331+
def remove_non_required_exceptions(docstring: Docstring) -> Docstring:
332+
"""Remove non-required exceptions from the docstring.
333+
334+
:param docstring: parsed docstring representation
335+
:returns: docstring representation with non-required exceptions removed
336+
"""
337+
# docstring.raises = [r for r in docstring.raises if r.type_name != 'Any']
338+
# return docstring
339+
for idx, itm in enumerate(docstring.meta):
340+
341+
if isinstance(itm, DocstringRaises):
342+
if itm.type_name == "Any":
343+
docstring.meta.pop(idx)
344+
345+
346+
return docstring
347+
348+
330349

331350

332351
def parse(text: str) -> Docstring:

PyDocSmith/tests/test_google.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,34 @@ def test_none_returns() -> None:
917917
assert len(docstring.many_returns) == 0
918918
print(compose(docstring))
919919

920+
def test_any_exception() -> None:
921+
"""Test parsing examples."""
922+
docstring = parse(
923+
"""A sample function
924+
925+
A function the demonstrates docstrings
926+
927+
Args:
928+
arg1 (int): The firsty arg
929+
930+
Exceptions:
931+
Any: Any exception that is coming
932+
933+
Returns:
934+
None
935+
"""
936+
)
937+
new_docstring = compose(docstring, rendering_style=RenderingStyle.COMPACT)
938+
print(new_docstring)
939+
docstring = parse(new_docstring)
940+
assert docstring is not None
941+
assert len(docstring.params) == 1
942+
assert len(docstring.raises) == 0
943+
944+
assert docstring.returns is None
945+
assert len(docstring.many_returns) == 0
946+
print(compose(docstring))
947+
920948

921949
def test_broken_meta() -> None:
922950
"""Test parsing broken meta."""

0 commit comments

Comments
 (0)