@@ -13,7 +13,7 @@ use crate::SchemaError;
13
13
use super :: { build_validator, BuildContext , BuildValidator , CombinedValidator , Extra , Validator } ;
14
14
15
15
#[ derive( Debug , Clone ) ]
16
- struct Argument {
16
+ struct Parameter {
17
17
positional : bool ,
18
18
name : String ,
19
19
kw_lookup_key : Option < LookupKey > ,
@@ -25,8 +25,8 @@ struct Argument {
25
25
26
26
#[ derive( Debug , Clone ) ]
27
27
pub struct ArgumentsValidator {
28
- arguments : Vec < Argument > ,
29
- positional_args_count : usize ,
28
+ parameters : Vec < Parameter > ,
29
+ positional_params_count : usize ,
30
30
var_args_validator : Option < Box < CombinedValidator > > ,
31
31
var_kwargs_validator : Option < Box < CombinedValidator > > ,
32
32
}
@@ -43,20 +43,20 @@ impl BuildValidator for ArgumentsValidator {
43
43
44
44
let populate_by_name = schema_or_config_same ( schema, config, intern ! ( py, "populate_by_name" ) ) ?. unwrap_or ( false ) ;
45
45
46
- let arguments_list : & PyList = schema. get_as_req ( intern ! ( py, "arguments_schema" ) ) ?;
47
- let mut arguments : Vec < Argument > = Vec :: with_capacity ( arguments_list . len ( ) ) ;
46
+ let arguments_schema : & PyList = schema. get_as_req ( intern ! ( py, "arguments_schema" ) ) ?;
47
+ let mut parameters : Vec < Parameter > = Vec :: with_capacity ( arguments_schema . len ( ) ) ;
48
48
49
- let mut positional_args_count = 0 ;
49
+ let mut positional_params_count = 0 ;
50
50
let mut had_default_arg = false ;
51
51
52
- for ( arg_index, arg) in arguments_list . iter ( ) . enumerate ( ) {
52
+ for ( arg_index, arg) in arguments_schema . iter ( ) . enumerate ( ) {
53
53
let arg: & PyDict = arg. cast_as ( ) ?;
54
54
55
55
let name: String = arg. get_as_req ( intern ! ( py, "name" ) ) ?;
56
56
let mode: & str = arg. get_as_req ( intern ! ( py, "mode" ) ) ?;
57
57
let positional = mode == "positional_only" || mode == "positional_or_keyword" ;
58
58
if positional {
59
- positional_args_count = arg_index + 1 ;
59
+ positional_params_count = arg_index + 1 ;
60
60
}
61
61
62
62
let mut kw_lookup_key = None ;
@@ -74,7 +74,7 @@ impl BuildValidator for ArgumentsValidator {
74
74
75
75
let schema: & PyAny = arg
76
76
. get_as_req ( intern ! ( py, "schema" ) )
77
- . map_err ( |err| SchemaError :: new_err ( format ! ( "Argument \" {}\" :\n {}" , name, err) ) ) ?;
77
+ . map_err ( |err| SchemaError :: new_err ( format ! ( "Parameter \" {}\" :\n {}" , name, err) ) ) ?;
78
78
79
79
let validator = build_validator ( schema, config, build_context) ?;
80
80
@@ -87,7 +87,7 @@ impl BuildValidator for ArgumentsValidator {
87
87
} else if default. is_some ( ) || default_factory. is_some ( ) {
88
88
had_default_arg = true ;
89
89
}
90
- arguments . push ( Argument {
90
+ parameters . push ( Parameter {
91
91
positional,
92
92
kw_lookup_key,
93
93
name,
@@ -99,8 +99,8 @@ impl BuildValidator for ArgumentsValidator {
99
99
}
100
100
101
101
Ok ( Self {
102
- arguments ,
103
- positional_args_count ,
102
+ parameters ,
103
+ positional_params_count ,
104
104
var_args_validator : match schema. get_item ( intern ! ( py, "var_args_schema" ) ) {
105
105
Some ( v) => Some ( Box :: new ( build_validator ( v, config, build_context) ?) ) ,
106
106
None => None ,
@@ -149,24 +149,24 @@ impl Validator for ArgumentsValidator {
149
149
) -> ValResult < ' data , PyObject > {
150
150
let args = input. validate_args ( ) ?;
151
151
152
- let mut output_args: Vec < PyObject > = Vec :: with_capacity ( self . positional_args_count ) ;
152
+ let mut output_args: Vec < PyObject > = Vec :: with_capacity ( self . positional_params_count ) ;
153
153
let output_kwargs = PyDict :: new ( py) ;
154
154
let mut errors: Vec < ValLineError > = Vec :: new ( ) ;
155
- let mut used_kwargs: AHashSet < & str > = AHashSet :: with_capacity ( self . arguments . len ( ) ) ;
155
+ let mut used_kwargs: AHashSet < & str > = AHashSet :: with_capacity ( self . parameters . len ( ) ) ;
156
156
157
157
macro_rules! process {
158
158
( $args: ident, $get_method: ident, $get_macro: ident, $slice_macro: ident) => { {
159
159
// go through arguments getting the value from args or kwargs and validating it
160
- for ( index, argument_info ) in self . arguments . iter( ) . enumerate( ) {
160
+ for ( index, parameter ) in self . parameters . iter( ) . enumerate( ) {
161
161
let mut pos_value = None ;
162
162
if let Some ( args) = $args. args {
163
- if argument_info . positional {
163
+ if parameter . positional {
164
164
pos_value = $get_macro!( args, index) ;
165
165
}
166
166
}
167
167
let mut kw_value = None ;
168
168
if let Some ( kwargs) = $args. kwargs {
169
- if let Some ( ref lookup_key) = argument_info . kw_lookup_key {
169
+ if let Some ( ref lookup_key) = parameter . kw_lookup_key {
170
170
if let Some ( ( key, value) ) = lookup_key. $get_method( kwargs) ? {
171
171
used_kwargs. insert( key) ;
172
172
kw_value = Some ( value) ;
@@ -179,11 +179,11 @@ impl Validator for ArgumentsValidator {
179
179
errors. push( ValLineError :: new_with_loc(
180
180
ErrorKind :: MultipleArgumentValues ,
181
181
kw_value,
182
- argument_info . name. clone( ) ,
182
+ parameter . name. clone( ) ,
183
183
) ) ;
184
184
}
185
185
( Some ( pos_value) , None ) => {
186
- match argument_info
186
+ match parameter
187
187
. validator
188
188
. validate( py, pos_value, extra, slots, recursion_guard)
189
189
{
@@ -195,71 +195,71 @@ impl Validator for ArgumentsValidator {
195
195
}
196
196
}
197
197
( None , Some ( kw_value) ) => {
198
- match argument_info
198
+ match parameter
199
199
. validator
200
200
. validate( py, kw_value, extra, slots, recursion_guard)
201
201
{
202
- Ok ( value) => output_kwargs. set_item( argument_info . kwarg_key. as_ref( ) . unwrap( ) , value) ?,
202
+ Ok ( value) => output_kwargs. set_item( parameter . kwarg_key. as_ref( ) . unwrap( ) , value) ?,
203
203
Err ( ValError :: LineErrors ( line_errors) ) => {
204
204
errors. extend(
205
205
line_errors
206
206
. into_iter( )
207
- . map( |err| err. with_outer_location( argument_info . name. clone( ) . into( ) ) ) ,
207
+ . map( |err| err. with_outer_location( parameter . name. clone( ) . into( ) ) ) ,
208
208
) ;
209
209
}
210
210
Err ( err) => return Err ( err) ,
211
211
}
212
212
}
213
213
( None , None ) => {
214
- if let Some ( ref default ) = argument_info . default {
215
- if let Some ( ref kwarg_key) = argument_info . kwarg_key {
214
+ if let Some ( ref default ) = parameter . default {
215
+ if let Some ( ref kwarg_key) = parameter . kwarg_key {
216
216
output_kwargs. set_item( kwarg_key, default ) ?;
217
217
} else {
218
218
output_args. push( default . clone_ref( py) ) ;
219
219
}
220
- } else if let Some ( ref default_factory) = argument_info . default_factory {
220
+ } else if let Some ( ref default_factory) = parameter . default_factory {
221
221
let default = default_factory. call0( py) ?;
222
- if let Some ( ref kwarg_key) = argument_info . kwarg_key {
222
+ if let Some ( ref kwarg_key) = parameter . kwarg_key {
223
223
output_kwargs. set_item( kwarg_key, default ) ?;
224
224
} else {
225
225
output_args. push( default ) ;
226
226
}
227
- } else if argument_info . kwarg_key. is_some( ) {
227
+ } else if parameter . kwarg_key. is_some( ) {
228
228
errors. push( ValLineError :: new_with_loc(
229
229
ErrorKind :: MissingKeywordArgument ,
230
230
input,
231
- argument_info . name. clone( ) ,
231
+ parameter . name. clone( ) ,
232
232
) ) ;
233
233
} else {
234
234
errors. push( ValLineError :: new_with_loc( ErrorKind :: MissingPositionalArgument , input, index) ) ;
235
235
} ;
236
236
}
237
237
}
238
238
}
239
- // if there are args check any where index > positional_args_count since they won't have been checked yet
239
+ // if there are args check any where index > positional_params_count since they won't have been checked yet
240
240
if let Some ( args) = $args. args {
241
241
let len = args. len( ) ;
242
- if len > self . positional_args_count {
242
+ if len > self . positional_params_count {
243
243
if let Some ( ref validator) = self . var_args_validator {
244
- for ( index, item) in $slice_macro!( args, self . positional_args_count , len) . iter( ) . enumerate( ) {
244
+ for ( index, item) in $slice_macro!( args, self . positional_params_count , len) . iter( ) . enumerate( ) {
245
245
match validator. validate( py, item, extra, slots, recursion_guard) {
246
246
Ok ( value) => output_args. push( value) ,
247
247
Err ( ValError :: LineErrors ( line_errors) ) => {
248
248
errors. extend(
249
249
line_errors
250
250
. into_iter( )
251
- . map( |err| err. with_outer_location( ( index + self . positional_args_count ) . into( ) ) ) ,
251
+ . map( |err| err. with_outer_location( ( index + self . positional_params_count ) . into( ) ) ) ,
252
252
) ;
253
253
}
254
254
Err ( err) => return Err ( err) ,
255
255
}
256
256
}
257
257
} else {
258
- for ( index, item) in $slice_macro!( args, self . positional_args_count , len) . iter( ) . enumerate( ) {
258
+ for ( index, item) in $slice_macro!( args, self . positional_params_count , len) . iter( ) . enumerate( ) {
259
259
errors. push( ValLineError :: new_with_loc(
260
260
ErrorKind :: UnexpectedPositionalArgument ,
261
261
item,
262
- index + self . positional_args_count ,
262
+ index + self . positional_params_count ,
263
263
) ) ;
264
264
}
265
265
}
0 commit comments