@@ -3494,6 +3494,120 @@ def arguments_schema(
34943494 )
34953495
34963496
3497+ class ArgumentsV3Parameter (TypedDict , total = False ):
3498+ name : Required [str ]
3499+ schema : Required [CoreSchema ]
3500+ mode : Literal [
3501+ 'positional_only' ,
3502+ 'positional_or_keyword' ,
3503+ 'keyword_only' ,
3504+ 'var_args' ,
3505+ 'var_kwargs_uniform' ,
3506+ 'var_kwargs_unpacked_typed_dict' ,
3507+ ] # default positional_or_keyword
3508+ alias : Union [str , list [Union [str , int ]], list [list [Union [str , int ]]]]
3509+
3510+
3511+ def arguments_v3_parameter (
3512+ name : str ,
3513+ schema : CoreSchema ,
3514+ * ,
3515+ mode : Literal [
3516+ 'positional_only' ,
3517+ 'positional_or_keyword' ,
3518+ 'keyword_only' ,
3519+ 'var_args' ,
3520+ 'var_kwargs_uniform' ,
3521+ 'var_kwargs_unpacked_typed_dict' ,
3522+ ]
3523+ | None = None ,
3524+ alias : str | list [str | int ] | list [list [str | int ]] | None = None ,
3525+ ) -> ArgumentsV3Parameter :
3526+ """
3527+ Returns a schema that matches an argument parameter, e.g.:
3528+
3529+ ```py
3530+ from pydantic_core import SchemaValidator, core_schema
3531+
3532+ param = core_schema.arguments_v3_parameter(
3533+ name='a', schema=core_schema.str_schema(), mode='positional_only'
3534+ )
3535+ schema = core_schema.arguments_v3_schema([param])
3536+ v = SchemaValidator(schema)
3537+ assert v.validate_python({'a': 'hello'}) == (('hello',), {})
3538+ ```
3539+
3540+ Args:
3541+ name: The name to use for the argument parameter
3542+ schema: The schema to use for the argument parameter
3543+ mode: The mode to use for the argument parameter
3544+ alias: The alias to use for the argument parameter
3545+ """
3546+ return _dict_not_none (name = name , schema = schema , mode = mode , alias = alias )
3547+
3548+
3549+ class ArgumentsV3Schema (TypedDict , total = False ):
3550+ type : Required [Literal ['arguments-v3' ]]
3551+ arguments_schema : Required [list [ArgumentsV3Parameter ]]
3552+ validate_by_name : bool
3553+ validate_by_alias : bool
3554+ extra_behavior : Literal ['forbid' , 'ignore' ] # 'allow' doesn't make sense here.
3555+ ref : str
3556+ metadata : dict [str , Any ]
3557+ serialization : SerSchema
3558+
3559+
3560+ def arguments_v3_schema (
3561+ arguments : list [ArgumentsV3Parameter ],
3562+ * ,
3563+ validate_by_name : bool | None = None ,
3564+ validate_by_alias : bool | None = None ,
3565+ extra_behavior : Literal ['forbid' , 'ignore' ] | None = None ,
3566+ ref : str | None = None ,
3567+ metadata : dict [str , Any ] | None = None ,
3568+ serialization : SerSchema | None = None ,
3569+ ) -> ArgumentsV3Schema :
3570+ """
3571+ Returns a schema that matches an arguments schema, e.g.:
3572+
3573+ ```py
3574+ from pydantic_core import SchemaValidator, core_schema
3575+
3576+ param_a = core_schema.arguments_v3_parameter(
3577+ name='a', schema=core_schema.str_schema(), mode='positional_only'
3578+ )
3579+ param_b = core_schema.arguments_v3_parameter(
3580+ name='kwargs', schema=core_schema.bool_schema(), mode='var_kwargs_uniform'
3581+ )
3582+ schema = core_schema.arguments_v3_schema([param_a, param_b])
3583+ v = SchemaValidator(schema)
3584+ assert v.validate_python({'a': 'hi', 'kwargs': {'b': True}}) == (('hi',), {'b': True})
3585+ ```
3586+
3587+ This schema is currently not used by other Pydantic components. In V3, it will most likely
3588+ become the default arguments schema for the `'call'` schema.
3589+
3590+ Args:
3591+ arguments: The arguments to use for the arguments schema.
3592+ validate_by_name: Whether to populate by the parameter names, defaults to `False`.
3593+ validate_by_alias: Whether to populate by the parameter aliases, defaults to `True`.
3594+ extra_behavior: The extra behavior to use.
3595+ ref: optional unique identifier of the schema, used to reference the schema in other places.
3596+ metadata: Any other information you want to include with the schema, not used by pydantic-core.
3597+ serialization: Custom serialization schema.
3598+ """
3599+ return _dict_not_none (
3600+ type = 'arguments-v3' ,
3601+ arguments_schema = arguments ,
3602+ validate_by_name = validate_by_name ,
3603+ validate_by_alias = validate_by_alias ,
3604+ extra_behavior = extra_behavior ,
3605+ ref = ref ,
3606+ metadata = metadata ,
3607+ serialization = serialization ,
3608+ )
3609+
3610+
34973611class CallSchema (TypedDict , total = False ):
34983612 type : Required [Literal ['call' ]]
34993613 arguments_schema : Required [CoreSchema ]
@@ -3921,6 +4035,7 @@ def definition_reference_schema(
39214035 DataclassArgsSchema ,
39224036 DataclassSchema ,
39234037 ArgumentsSchema ,
4038+ ArgumentsV3Schema ,
39244039 CallSchema ,
39254040 CustomErrorSchema ,
39264041 JsonSchema ,
@@ -3978,6 +4093,7 @@ def definition_reference_schema(
39784093 'dataclass-args' ,
39794094 'dataclass' ,
39804095 'arguments' ,
4096+ 'arguments-v3' ,
39814097 'call' ,
39824098 'custom-error' ,
39834099 'json' ,
0 commit comments