ArgumentsValidator
This class provides functionality for validating function arguments against a defined set of parameters, including support for positional and keyword arguments. It manages complex validation scenarios such as variable arguments (var_args), variable keyword arguments (var_kwargs), and alias-based mapping. The validator also handles extra argument behaviors and configurable naming conventions to ensure input data conforms to the expected schema.
Attributes
| Attribute | Type | Description |
|---|---|---|
| parameters | Vec< Parameter > | A collection of Parameter objects used to define the schema and validation rules for individual arguments. |
| positional_params_count | usize | The total number of arguments that can be passed positionally to the function or class. |
| var_args_validator | Option< Arc< CombinedValidator > > | An optional validator applied to all additional positional arguments captured via *args. |
| var_kwargs_mode | [VarKwargsMode](varkwargsmode.md?sid=validators_arguments_varkwargsmode) | Determines the specific behavior and handling strategy for variable keyword arguments. |
| var_kwargs_validator | Option< Arc< CombinedValidator > > | An optional validator applied to all additional keyword arguments captured via **kwargs. |
| loc_by_alias | bool | A flag indicating whether error locations should be reported using the attribute's alias instead of its internal name. |
| extra | [ExtraBehavior](../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior) | Defines the behavior when encountering unexpected arguments, such as allowing, forbidding, or ignoring them. |
| validate_by_alias | Option< bool > | An optional override to determine if validation should prioritize the alias names of the arguments. |
| validate_by_name | Option< bool > | An optional override to determine if validation should prioritize the internal field names of the arguments. |
Constructor
Signature
def ArgumentsValidator(
parameters: Vec< Parameter >,
positional_params_count: usize,
var_args_validator: Option< Arc< CombinedValidator > >,
var_kwargs_mode: [VarKwargsMode](varkwargsmode.md?sid=validators_arguments_varkwargsmode),
var_kwargs_validator: Option< Arc< CombinedValidator > >,
loc_by_alias: bool,
extra: [ExtraBehavior](../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior),
validate_by_alias: Option< bool >,
validate_by_name: Option< bool >
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| parameters | Vec< Parameter > | A list of parameter definitions to validate against. |
| positional_params_count | usize | The number of parameters that can be passed positionally. |
| var_args_validator | Option< Arc< CombinedValidator > > | Optional validator for variable positional arguments (*args). |
| var_kwargs_mode | [VarKwargsMode](varkwargsmode.md?sid=validators_arguments_varkwargsmode) | The mode defining how variable keyword arguments are handled. |
| var_kwargs_validator | Option< Arc< CombinedValidator > > | Optional validator for variable keyword arguments (**kwargs). |
| loc_by_alias | bool | Whether to use aliases in error locations. |
| extra | [ExtraBehavior](../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior) | Defines the behavior when extra arguments are provided. |
| validate_by_alias | Option< bool > | Whether to validate input using field aliases. |
| validate_by_name | Option< bool > | Whether to validate input using field names. |
Methods
validate()
def validate(
args: tuple,
kwargs: dict
) - > dict
Validates the provided arguments against the defined parameters, handling positional, keyword, and variadic arguments according to the configured validation modes.
Parameters
| Name | Type | Description |
|---|---|---|
| args | tuple | The positional arguments passed to the function or method. |
| kwargs | dict | The keyword arguments passed to the function or method. |
Returns
| Type | Description |
|---|---|
dict | A dictionary of validated arguments mapped to their respective parameter names. |