Skip to content

Commit 72619fc

Browse files
committed
Merge branch 'main' of github.com:mkdocstrings/griffe-typingdoc
2 parents fc50541 + 6e6eea8 commit 72619fc

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88
<!-- insertion marker -->
9-
## [0.2.5](https://github.com/mkdocstrings/griffe-typingdoc/releases/tag/0.2.5) - 2024-08-14
9+
## [0.2.5](https://github.com/mkdocstrings/griffe-typingdoc/releases/tag/0.2.5) - 2024-02-08
1010

1111
<small>[Compare with 0.2.4](https://github.com/mkdocstrings/griffe-typingdoc/compare/0.2.4...0.2.5)</small>
1212

13-
### Build
13+
### Bug Fixes
1414

15-
- Depend on Griffe 0.49 ([b6d7bd9](https://github.com/mkdocstrings/griffe-typingdoc/commit/b6d7bd9ce462a8dbd067464b3d14a9dd25865957) by Timothée Mazzucotelli).
15+
- Support simple return annotations ([b4afabe](https://github.com/mkdocstrings/griffe-typingdoc/commit/b4afabed86e8b7c1905cbf672ab261be0d895e40) by Timothée Mazzucotelli). [Issue #9](https://github.com/mkdocstrings/griffe-typingdoc/issues/9)
1616

1717
## [0.2.4](https://github.com/mkdocstrings/griffe-typingdoc/releases/tag/0.2.4) - 2023-11-14
1818

src/griffe_typingdoc/_static.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ def _returns_docs(func: Function, **kwargs: Any) -> DocstringSectionReturns | No
195195
"typing_extensions.Generator",
196196
}:
197197
return_annotation = annotation.slice.elements[2] # type: ignore[attr-defined]
198+
elif isinstance(annotation, ExprSubscript) and annotation.canonical_path in {
199+
"typing.Annotated",
200+
"typing_extensions.Annotated",
201+
}:
202+
return_annotation = annotation
198203

199204
if return_annotation:
200205
if isinstance(return_annotation, ExprSubscript) and return_annotation.is_tuple:

tests/test_extension.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
)
1010
warning_imports = "from warnings import deprecated"
1111

12+
# NOTE: Important! The value in calls to `Doc` will be parsed as a Name expression
13+
# if it is valid Python syntax for names. To make sure it is correctly parsed as a string,
14+
# it must contain invalid syntax for names, such as a dot at the end.
15+
# The alternative solution would be to add `from __future__ import annotations`
16+
# at the beginning of each temporary visited module.
17+
1218

1319
def test_extension_on_itself() -> None:
1420
"""Load our own package using the extension, assert a parameters section is added to the parsed docstring."""
@@ -131,3 +137,13 @@ def f() -> Generator[
131137
assert sections[2].value[1].description == "Second received."
132138
assert sections[3].value[0].description == "First returned."
133139
assert sections[3].value[1].description == "Second returned."
140+
141+
142+
def test_return_doc() -> None:
143+
"""Read documentation for return value."""
144+
with temporary_visited_package(
145+
"package",
146+
modules={"__init__.py": f"{typing_imports}\ndef f() -> Annotated[int, Doc('Hello.')]: ..."},
147+
extensions=Extensions(TypingDocExtension()),
148+
) as package:
149+
assert package["f"].docstring.parsed[1].value[0].description == "Hello."

0 commit comments

Comments
 (0)