Skip to content

Commit

Permalink
fix: Log debug instead of errors when failing to parse NumPy annotati…
Browse files Browse the repository at this point in the history
…ons for additional sections

Issue #93: #93
PR #109: #109
  • Loading branch information
sisp committed Oct 26, 2022
1 parent 2fff908 commit 568ff60
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/griffe/docstrings/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def _read_returns_section( # noqa: WPS231
else:
annotation = return_item
else:
annotation = parse_annotation(annotation, docstring) # type: ignore[arg-type]
annotation = parse_annotation(annotation, docstring, log_level=LogLevel.debug) # type: ignore[arg-type]
returns.append(DocstringReturn(name=name or "", annotation=annotation, description=text))
return DocstringSectionReturns(returns), new_offset

Expand Down Expand Up @@ -423,7 +423,7 @@ def _read_yields_section( # noqa: WPS231
else:
annotation = yield_item
else:
annotation = parse_annotation(annotation, docstring) # type: ignore[arg-type]
annotation = parse_annotation(annotation, docstring, log_level=LogLevel.debug) # type: ignore[arg-type]
yields.append(DocstringYield(name=name or "", annotation=annotation, description=text))
return DocstringSectionYields(yields), new_offset

Expand Down Expand Up @@ -465,7 +465,7 @@ def _read_receives_section( # noqa: WPS231
else:
annotation = receives_item
else:
annotation = parse_annotation(annotation, docstring) # type: ignore[arg-type]
annotation = parse_annotation(annotation, docstring, log_level=LogLevel.debug) # type: ignore[arg-type]
receives.append(DocstringReceive(name=name or "", annotation=annotation, description=text))
return DocstringSectionReceives(receives), new_offset

Expand Down Expand Up @@ -543,7 +543,7 @@ def _read_attributes_section(
with suppress(AttributeError, KeyError):
annotation = docstring.parent.members[name].annotation # type: ignore[union-attr]
else:
annotation = parse_annotation(annotation, docstring) # type: ignore[arg-type]
annotation = parse_annotation(annotation, docstring, log_level=LogLevel.debug) # type: ignore[arg-type]
text = dedent("\n".join(item[1:]))
attributes.append(DocstringAttribute(name=name, annotation=annotation, description=text))
return DocstringSectionAttributes(attributes), new_offset
Expand Down
20 changes: 20 additions & 0 deletions tests/test_docstrings/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,30 @@ def test_dont_crash_on_text_annotations(parse_numpy, caplog):
caplog: Pytest fixture used to capture logs.
"""
docstring = """
Attributes
----------
region : str, list-like, geopandas.GeoSeries, geopandas.GeoDataFrame, geometric
Description.
Parameters
----------
region : str, list-like, geopandas.GeoSeries, geopandas.GeoDataFrame, geometric
Description.
Returns
-------
str or bytes
Description.
Receives
--------
region : str, list-like, geopandas.GeoSeries, geopandas.GeoDataFrame, geometric
Description.
Yields
------
str or bytes
Description.
"""
caplog.set_level(logging.DEBUG)
assert parse_numpy(docstring, parent=Function("f"))
Expand Down

0 comments on commit 568ff60

Please sign in to comment.