Skip to content
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

fix: Log debug instead of errors when failing to parse NumPy annotations for additional sections #109

Merged
merged 1 commit into from
Oct 26, 2022
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 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