@@ -147,3 +147,58 @@ def test_return_doc() -> None:
147
147
extensions = Extensions (TypingDocExtension ()),
148
148
) as package :
149
149
assert package ["f" ].docstring .parsed [1 ].value [0 ].description == "Hello."
150
+
151
+
152
+ def test_unpacking_typed_dict () -> None :
153
+ """Unpack typed dicts, resolving them to their right location."""
154
+ with temporary_visited_package (
155
+ "package" ,
156
+ {
157
+ "__init__.py" : """
158
+ from typing import TypedDict
159
+ from typing_extensions import Annotated, Doc, Unpack
160
+
161
+ from package import module
162
+
163
+ class Options(TypedDict):
164
+ foo: Annotated[int, Doc("Foo's description.")]
165
+
166
+ class A:
167
+ def __init__(self, **kwargs: Unpack[Options]) -> None:
168
+ '''Init.'''
169
+ self.options = kwargs
170
+
171
+ class B:
172
+ def __init__(self, **kwargs: Unpack[module.Options]) -> None:
173
+ '''Init.'''
174
+ self.options = kwargs
175
+ """ ,
176
+ "module.py" : """
177
+ from typing import TypedDict
178
+ from typing_extensions import Annotated, Doc
179
+
180
+ class Options(TypedDict):
181
+ bar: Annotated[str, Doc("Bar's description.")]
182
+ """ ,
183
+ },
184
+ extensions = Extensions (TypingDocExtension ()),
185
+ ) as package :
186
+ sections = package ["A.__init__" ].docstring .parsed
187
+ assert len (sections ) == 3
188
+ assert sections [0 ].kind is DocstringSectionKind .text
189
+ assert sections [1 ].kind is DocstringSectionKind .parameters
190
+ assert sections [2 ].kind is DocstringSectionKind .other_parameters
191
+ foo = sections [2 ].value [0 ]
192
+ assert foo .name == "foo"
193
+ assert foo .description == "Foo's description."
194
+ assert str (foo .annotation ).startswith ("Annotated[int" )
195
+
196
+ sections = package ["B.__init__" ].docstring .parsed
197
+ assert len (sections ) == 3
198
+ assert sections [0 ].kind is DocstringSectionKind .text
199
+ assert sections [1 ].kind is DocstringSectionKind .parameters
200
+ assert sections [2 ].kind is DocstringSectionKind .other_parameters
201
+ bar = sections [2 ].value [0 ]
202
+ assert bar .name == "bar"
203
+ assert bar .description == "Bar's description."
204
+ assert str (bar .annotation ).startswith ("Annotated[str" )
0 commit comments