File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -180,7 +180,11 @@ def _transform_recursive(
180180 return _transform_typeddict (data , stripped_type )
181181
182182 if origin == dict and is_mapping (data ):
183- items_type = get_args (stripped_type )[1 ]
183+ args = get_args (stripped_type )
184+ if len (args ) < 2 :
185+ return data
186+
187+ items_type = args [1 ]
184188 return {key : _transform_recursive (value , annotation = items_type ) for key , value in data .items ()}
185189
186190 if (
@@ -346,7 +350,11 @@ async def _async_transform_recursive(
346350 return await _async_transform_typeddict (data , stripped_type )
347351
348352 if origin == dict and is_mapping (data ):
349- items_type = get_args (stripped_type )[1 ]
353+ args = get_args (stripped_type )
354+ if len (args ) < 2 :
355+ return data
356+
357+ items_type = args [1 ]
350358 return {key : _transform_recursive (value , annotation = items_type ) for key , value in data .items ()}
351359
352360 if (
Original file line number Diff line number Diff line change @@ -154,6 +154,18 @@ class Bar7(TypedDict):
154154 foo : str
155155
156156
157+ class Foo7BareDict (TypedDict ):
158+ metadata : dict
159+
160+
161+ @parametrize
162+ @pytest .mark .asyncio
163+ async def test_bare_dict_typeddict_field (use_async : bool ) -> None :
164+ data = {"metadata" : {"key" : "value" }}
165+
166+ assert await transform (data , Foo7BareDict , use_async ) == data
167+
168+
157169@parametrize
158170@pytest .mark .asyncio
159171async def test_ignores_invalid_input (use_async : bool ) -> None :
You can’t perform that action at this time.
0 commit comments