|
7 | 7 |
|
8 | 8 | from griffe_typingdoc import TypingDocExtension |
9 | 9 |
|
10 | | -typing_imports = "from typing import Annotated, Doc, Generator, Iterator, Name, NotRequired, Raises, TypedDict, Unpack, Warns" |
| 10 | +typing_imports = ( |
| 11 | + "from typing import Annotated, Doc, Generator, Iterator, Name, NotRequired, Raises, TypedDict, Unpack, Warns" |
| 12 | +) |
11 | 13 | warning_imports = "from warnings import deprecated" |
12 | 14 |
|
| 15 | +# NOTE: Important! The value in calls to `Doc` will be parsed as a Name expression |
| 16 | +# if it is valid Python syntax for names. To make sure it is correctly parsed as a string, |
| 17 | +# it must contain invalid syntax for names, such as a dot at the end. |
| 18 | +# The alternative solution would be to add `from __future__ import annotations` |
| 19 | +# at the beginning of each temporary visited module. |
| 20 | + |
13 | 21 |
|
14 | 22 | def test_extension_on_itself() -> None: |
15 | 23 | """Load our own package using the extension, assert a parameters section is added to the parsed docstring.""" |
@@ -41,7 +49,6 @@ def test_parameter_doc() -> None: |
41 | 49 | assert package["f"].docstring.parsed[1].value[0].description == "Hello." |
42 | 50 |
|
43 | 51 |
|
44 | | - |
45 | 52 | def test_other_parameter_doc() -> None: |
46 | 53 | """Read documentation for other parameters, in unpack/typeddict annotations.""" |
47 | 54 | with temporary_visited_package( |
@@ -133,3 +140,13 @@ def f() -> Generator[ |
133 | 140 | assert sections[2].value[1].description == "Second received." |
134 | 141 | assert sections[3].value[0].description == "First returned." |
135 | 142 | assert sections[3].value[1].description == "Second returned." |
| 143 | + |
| 144 | + |
| 145 | +def test_return_doc() -> None: |
| 146 | + """Read documentation for return value.""" |
| 147 | + with temporary_visited_package( |
| 148 | + "package", |
| 149 | + modules={"__init__.py": f"{typing_imports}\ndef f() -> Annotated[int, Doc('Hello.')]: ..."}, |
| 150 | + extensions=Extensions(TypingDocExtension()), |
| 151 | + ) as package: |
| 152 | + assert package["f"].docstring.parsed[1].value[0].description == "Hello." |
0 commit comments