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: numpy returns handles more name, type cases #174

Merged
merged 6 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/griffe/docstrings/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ def _read_block(docstring: Docstring, *, offset: int) -> tuple[str, int]:
| # or
(?P<name>{_RE_NAME})\s*:\s* # just name
| # or
(?P<type>{_RE_TYPE})\s* # just type
\s*:$ # no name, no type
|
:?\s*(?P<type>{_RE_TYPE})\s* # just type
pawamoy marked this conversation as resolved.
Show resolved Hide resolved
)
""",
re.IGNORECASE | re.VERBOSE,
Expand Down
21 changes: 21 additions & 0 deletions tests/test_docstrings/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ def test_returns_section(parse_numpy: ParserType) -> None:
flag : bool
Some kind
of flag.
x :
Name only
:
No name or annotation
: int
Only annotation
"""

sections, _ = parse_numpy(docstring)
Expand All @@ -367,6 +373,21 @@ def test_returns_section(parse_numpy: ParserType) -> None:
DocstringReturn(name="", annotation="bool", description="Some kind\nof flag."),
)

assert_element_equal(
sections[0].value[2],
DocstringReturn(name="", annotation=None, description="Name only"),
pawamoy marked this conversation as resolved.
Show resolved Hide resolved
)

assert_element_equal(
sections[0].value[3],
DocstringReturn(name="", annotation=None, description="No name or annotation"),
)

assert_element_equal(
sections[0].value[4],
DocstringReturn(name="", annotation="int", description="Only annotation"),
)


def test_yields_section(parse_numpy: ParserType) -> None:
"""Parse yields section.
Expand Down
Loading