99from dataclasses import dataclass , field
1010from functools import partial
1111from inspect import Parameter , signature
12- from typing import TYPE_CHECKING , Any , Concatenate , cast , get_origin
12+ from typing import TYPE_CHECKING , Any , Concatenate , Literal , cast , get_origin
1313
1414from pydantic import ConfigDict
1515from pydantic ._internal import _decorators , _generate_schema , _typing_extra
@@ -184,10 +184,8 @@ def function_schema( # noqa: C901
184184 raise UserError (f'Error generating schema for { function .__qualname__ } :\n { error_details } ' )
185185
186186 core_config = config_wrapper .core_config (None )
187- # noinspection PyTypedDict
188- core_config ['extra_fields_behavior' ] = 'allow' if var_kwargs_schema else 'forbid'
189187
190- schema , single_arg_name = _build_schema (fields , var_kwargs_schema , gen_schema , core_config )
188+ schema , single_arg_name = _build_schema (fields , var_kwargs_schema , core_config )
191189 schema = gen_schema .clean_schema (schema )
192190 # noinspection PyUnresolvedReferences
193191 schema_validator = create_schema_validator (
@@ -269,15 +267,13 @@ def _takes_ctx(callable_obj: TargetCallable[P, R]) -> TypeIs[WithCtx[P, R]]: #
269267def _build_schema (
270268 fields : dict [str , core_schema .TypedDictField ],
271269 var_kwargs_schema : core_schema .CoreSchema | None ,
272- gen_schema : _generate_schema .GenerateSchema ,
273270 core_config : core_schema .CoreConfig ,
274271) -> tuple [core_schema .CoreSchema , str | None ]:
275272 """Generate a typed dict schema for function parameters.
276273
277274 Args:
278275 fields: The fields to generate a typed dict schema for.
279276 var_kwargs_schema: The variable keyword arguments schema.
280- gen_schema: The `GenerateSchema` instance.
281277 core_config: The core configuration.
282278
283279 Returns:
@@ -289,10 +285,12 @@ def _build_schema(
289285 if td_field ['metadata' ]['is_model_like' ]: # type: ignore
290286 return td_field ['schema' ], name
291287
288+ extra_behavior : Literal ['allow' , 'forbid' ] = 'allow' if var_kwargs_schema else 'forbid'
292289 td_schema = core_schema .typed_dict_schema (
293290 fields ,
294291 config = core_config ,
295- extras_schema = gen_schema .generate_schema (var_kwargs_schema ) if var_kwargs_schema else None ,
292+ extra_behavior = extra_behavior ,
293+ extras_schema = var_kwargs_schema ,
296294 )
297295 return td_schema , None
298296
0 commit comments