-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Support documenting multiple items for optional tuples
- Loading branch information
Showing
2 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Test names and expressions methods.""" | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from griffe.docstrings.parsers import Parser | ||
from tests.helpers import temporary_visited_module | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("annotation", "items"), | ||
[ | ||
("tuple[int, float] | None", 2), | ||
("None | tuple[int, float]", 2), | ||
("Optional[tuple[int, float]]", 2), | ||
("typing.Optional[tuple[int, float]]", 2), | ||
], | ||
) | ||
def test_explode_return_annotations(annotation, items): | ||
"""Check that we correctly split items from return annotations. | ||
Parameters: | ||
annotation: The return annotation. | ||
items: The number of items to write in the docstring returns section. | ||
""" | ||
newline = "\n " | ||
returns = newline.join(f"x{_}: Some value." for _ in range(items)) | ||
code = f""" | ||
import typing | ||
from typing import Optional | ||
def function() -> {annotation}: | ||
'''This function returns either two ints or None | ||
Returns: | ||
{returns} | ||
''' | ||
""" | ||
with temporary_visited_module(code) as module: | ||
sections = module["function"].docstring.parse(Parser.google) | ||
assert sections[1].value |