@@ -10,7 +10,9 @@ use pyo3::IntoPyObjectExt;
10
10
use crate :: build_tools:: py_schema_err;
11
11
use crate :: build_tools:: { schema_or_config_same, ExtraBehavior } ;
12
12
use crate :: errors:: { ErrorTypeDefaults , ValError , ValLineError , ValResult } ;
13
- use crate :: input:: { Arguments , BorrowInput , Input , KeywordArgs , PositionalArgs , ValidatedDict , ValidationMatch } ;
13
+ use crate :: input:: {
14
+ Arguments , BorrowInput , Input , KeywordArgs , PositionalArgs , ValidatedDict , ValidatedTuple , ValidationMatch ,
15
+ } ;
14
16
use crate :: lookup_key:: LookupKey ;
15
17
use crate :: tools:: SchemaDict ;
16
18
@@ -209,11 +211,29 @@ impl ArgumentsV3Validator {
209
211
Err ( err) => return Err ( err) ,
210
212
}
211
213
}
212
- // ParameterMode::VarArgs => match dict_value.validate_tuple() {
213
- // Ok(iterable) => for value in iterable,
214
- // Err(err) => return Err(err),
215
- // },
216
- ParameterMode :: VarArgs => todo ! ( ) ,
214
+ ParameterMode :: VarArgs => match dict_value. borrow_input ( ) . validate_tuple ( false ) {
215
+ Ok ( tuple) => {
216
+ tuple. unpack ( state) . try_for_each ( |v| {
217
+ match parameter. validator . validate ( py, v. unwrap ( ) . borrow_input ( ) , state) {
218
+ Ok ( tuple_value) => {
219
+ output_args. push ( tuple_value) ;
220
+ return Ok ( ( ) ) ;
221
+ }
222
+ Err ( ValError :: LineErrors ( line_errors) ) => {
223
+ errors. extend ( line_errors. into_iter ( ) . map ( |err| {
224
+ lookup_path. apply_error_loc ( err, self . loc_by_alias , & parameter. name )
225
+ } ) ) ;
226
+ return Ok ( ( ) ) ;
227
+ }
228
+ Err ( err) => return Err ( err) ,
229
+ }
230
+ } ) ?;
231
+ }
232
+ Err ( _) => {
233
+ let val_error = ValLineError :: new ( ErrorTypeDefaults :: TupleType , dict_value. borrow_input ( ) ) ;
234
+ errors. push ( lookup_path. apply_error_loc ( val_error, self . loc_by_alias , & parameter. name ) ) ;
235
+ }
236
+ } ,
217
237
ParameterMode :: KeywordOnly => {
218
238
match parameter. validator . validate ( py, dict_value. borrow_input ( ) , state) {
219
239
Ok ( value) => {
@@ -240,6 +260,7 @@ impl ArgumentsV3Validator {
240
260
for err in line_errors {
241
261
errors. push (
242
262
err. with_outer_location ( dict_key. clone ( ) )
263
+ . with_outer_location ( & parameter. name )
243
264
. with_type ( ErrorTypeDefaults :: InvalidKey ) ,
244
265
) ;
245
266
}
@@ -252,14 +273,21 @@ impl ArgumentsV3Validator {
252
273
Ok ( value) => output_kwargs. set_item ( dict_key, value) ?,
253
274
Err ( ValError :: LineErrors ( line_errors) ) => {
254
275
errors. extend ( line_errors. into_iter ( ) . map ( |err| {
255
- lookup_path. apply_error_loc ( err, self . loc_by_alias , & parameter. name )
276
+ lookup_path. apply_error_loc (
277
+ err. with_outer_location ( dict_key. clone ( ) ) ,
278
+ self . loc_by_alias ,
279
+ & parameter. name ,
280
+ )
256
281
} ) ) ;
257
282
}
258
283
Err ( err) => return Err ( err) ,
259
284
}
260
285
}
261
286
}
262
- None => todo ! ( ) ,
287
+ None => {
288
+ let val_error = ValLineError :: new ( ErrorTypeDefaults :: DictType , dict_value) ;
289
+ errors. push ( lookup_path. apply_error_loc ( val_error, self . loc_by_alias , & parameter. name ) ) ;
290
+ }
263
291
} ,
264
292
ParameterMode :: VarKwargsUnpackedTypedDict => {
265
293
let kwargs_dict = dict_value
0 commit comments