From 0b43e5c6001044e9ad56bcba49bf192cd64132d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 10 Sep 2024 18:36:37 +0200 Subject: [PATCH 1/3] style: Format --- duties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/duties.py b/duties.py index 902a80d..138ae30 100644 --- a/duties.py +++ b/duties.py @@ -54,7 +54,7 @@ def changelog(ctx: Context, bump: str = "") -> None: @duty(pre=["check_quality", "check_types", "check_docs", "check_dependencies", "check-api"]) -def check(ctx: Context) -> None: # noqa: ARG001 +def check(ctx: Context) -> None: """Check it all!""" From 5e06b33651f43b292059d27d3b232e2646a409d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 10 Sep 2024 18:37:43 +0200 Subject: [PATCH 2/3] fix: Resolve names in `Unpack`, instead of naively trying to get them from the parent of the function being handled Issue-11: https://github.com/mkdocstrings/griffe-typingdoc/issues/11 --- src/griffe_typingdoc/_static.py | 3 +- tests/test_extension.py | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/griffe_typingdoc/_static.py b/src/griffe_typingdoc/_static.py index ead6ecf..8aa1f96 100644 --- a/src/griffe_typingdoc/_static.py +++ b/src/griffe_typingdoc/_static.py @@ -127,7 +127,8 @@ def _other_parameters_docs(func: Function, **kwargs: Any) -> DocstringSectionPar "typing.Unpack", "typing_extensions.Unpack", }: - typed_dict = annotation.slice.parent.get_member(annotation.slice.name) # type: ignore[attr-defined] + slice_path = annotation.slice.canonical_path + typed_dict = func.modules_collection[slice_path] params_doc = { attr.name: {"annotation": attr.annotation, "description": _metadata(attr.annotation).get("doc", "")} for attr in typed_dict.members.values() diff --git a/tests/test_extension.py b/tests/test_extension.py index 5a470aa..b7ca900 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -147,3 +147,58 @@ def test_return_doc() -> None: extensions=Extensions(TypingDocExtension()), ) as package: assert package["f"].docstring.parsed[1].value[0].description == "Hello." + + +def test_unpacking_typed_dict() -> None: + """Unpack typed dicts, resolving them to their right location.""" + with temporary_visited_package( + "package", + { + "__init__.py": """ + from typing import TypedDict + from typing_extensions import Annotated, Doc, Unpack + + from package import module + + class Options(TypedDict): + foo: Annotated[int, Doc("Foo's description.")] + + class A: + def __init__(self, **kwargs: Unpack[Options]) -> None: + '''Init.''' + self.options = kwargs + + class B: + def __init__(self, **kwargs: Unpack[module.Options]) -> None: + '''Init.''' + self.options = kwargs + """, + "module.py": """ + from typing import TypedDict + from typing_extensions import Annotated, Doc + + class Options(TypedDict): + bar: Annotated[str, Doc("Bar's description.")] + """, + }, + extensions=Extensions(TypingDocExtension()), + ) as package: + sections = package["A.__init__"].docstring.parsed + assert len(sections) == 3 + assert sections[0].kind is DocstringSectionKind.text + assert sections[1].kind is DocstringSectionKind.parameters + assert sections[2].kind is DocstringSectionKind.other_parameters + foo = sections[2].value[0] + assert foo.name == "foo" + assert foo.description == "Foo's description." + assert str(foo.annotation).startswith("Annotated[int") + + sections = package["B.__init__"].docstring.parsed + assert len(sections) == 3 + assert sections[0].kind is DocstringSectionKind.text + assert sections[1].kind is DocstringSectionKind.parameters + assert sections[2].kind is DocstringSectionKind.other_parameters + bar = sections[2].value[0] + assert bar.name == "bar" + assert bar.description == "Bar's description." + assert str(bar.annotation).startswith("Annotated[str") From 1d0ca42992c3a73cd4444a57ae6a28f84259e454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 10 Sep 2024 18:38:04 +0200 Subject: [PATCH 3/3] chore: Prepare release 0.2.7 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58cab65..1eb8130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.2.7](https://github.com/mkdocstrings/griffe-typingdoc/releases/tag/0.2.7) - 2024-09-10 + +[Compare with 0.2.6](https://github.com/mkdocstrings/griffe-typingdoc/compare/0.2.6...0.2.7) + +### Bug Fixes + +- Resolve names in `Unpack`, instead of naively trying to get them from the parent of the function being handled ([5e06b33](https://github.com/mkdocstrings/griffe-typingdoc/commit/5e06b33651f43b292059d27d3b232e2646a409d5) by Timothée Mazzucotelli). [Issue-11](https://github.com/mkdocstrings/griffe-typingdoc/issues/11) + ## [0.2.6](https://github.com/mkdocstrings/griffe-typingdoc/releases/tag/0.2.6) - 2024-08-14 [Compare with 0.2.5](https://github.com/mkdocstrings/griffe-typingdoc/compare/0.2.5...0.2.6)