Skip to content

Commit e69d454

Browse files
committed
Convert PyFuncArgs.kwargs to a Vec
Instead of an Option<Vec>
1 parent ad0d03b commit e69d454

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

vm/src/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ pub fn builtin_build_class_(vm: &mut VirtualMachine, mut args: PyFuncArgs) -> Py
419419
function,
420420
PyFuncArgs {
421421
args: vec![namespace.clone()],
422-
kwargs: None,
422+
kwargs: vec![],
423423
},
424424
);
425425
objtype::new(metaclass, name, bases, namespace)

vm/src/obj/objtype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn get_attribute(vm: &mut VirtualMachine, obj: PyObjectRef, name: &String) -
131131
descriptor,
132132
PyFuncArgs {
133133
args: vec![attr, obj, cls],
134-
kwargs: None,
134+
kwargs: vec![],
135135
},
136136
);
137137
}

vm/src/pyobject.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl fmt::Debug for PyObject {
512512
#[derive(Debug, Default, Clone)]
513513
pub struct PyFuncArgs {
514514
pub args: Vec<PyObjectRef>,
515-
pub kwargs: Option<Vec<(String, PyObjectRef)>>,
515+
pub kwargs: Vec<(String, PyObjectRef)>,
516516
}
517517

518518
impl PyFuncArgs {
@@ -523,7 +523,7 @@ impl PyFuncArgs {
523523
}
524524
PyFuncArgs {
525525
args: args,
526-
kwargs: Some(kwargs),
526+
kwargs: kwargs,
527527
}
528528
}
529529

vm/src/vm.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl VirtualMachine {
6363
let args: Vec<PyObjectRef> = Vec::new();
6464
let args = PyFuncArgs {
6565
args: args,
66-
kwargs: None,
66+
kwargs: vec![],
6767
};
6868

6969
// Call function:
@@ -270,7 +270,7 @@ impl VirtualMachine {
270270
self,
271271
PyFuncArgs {
272272
args: vec![traceback, pos],
273-
kwargs: None,
273+
kwargs: vec![],
274274
},
275275
).unwrap();
276276
// exception.__trace
@@ -354,7 +354,7 @@ impl VirtualMachine {
354354
};
355355
let args = PyFuncArgs {
356356
args: args,
357-
kwargs: None,
357+
kwargs: vec![],
358358
};
359359
self.invoke(func, args)
360360
}
@@ -503,7 +503,7 @@ impl VirtualMachine {
503503
}
504504
}
505505

506-
pub fn invoke(&mut self, func_ref: PyObjectRef, mut args: PyFuncArgs) -> PyResult {
506+
pub fn invoke(&mut self, func_ref: PyObjectRef, args: PyFuncArgs) -> PyResult {
507507
trace!("Invoke: {:?} {:?}", func_ref, args);
508508
match func_ref.borrow().kind {
509509
PyObjectKind::RustFunction { function } => function(self, args),
@@ -534,22 +534,20 @@ impl VirtualMachine {
534534
// TODO: Pack other positional arguments in to *args
535535

536536
// Handle keyword arguments
537-
if let Some(ref mut kwargs) = args.kwargs {
538-
for (name, value) in kwargs {
539-
if !code_object.arg_names.contains(&name) {
540-
return Err(self.new_type_error(format!(
541-
"Got an unexpected keyword argument '{}'",
542-
name
543-
)));
544-
}
545-
if scope.contains_key(&name) {
546-
return Err(self.new_type_error(format!(
547-
"Got multiple values for argument '{}'",
548-
name
549-
)));
550-
}
551-
scope.set_item(&name, value.clone());
537+
for (name, value) in args.kwargs {
538+
if !code_object.arg_names.contains(&name) {
539+
return Err(self.new_type_error(format!(
540+
"Got an unexpected keyword argument '{}'",
541+
name
542+
)));
543+
}
544+
if scope.contains_key(&name) {
545+
return Err(self.new_type_error(format!(
546+
"Got multiple values for argument '{}'",
547+
name
548+
)));
552549
}
550+
scope.set_item(&name, value.clone());
553551
}
554552

555553
// Add missing positional arguments, if we have fewer positional arguments than the
@@ -870,7 +868,7 @@ impl VirtualMachine {
870868
let args: Vec<PyObjectRef> = self.pop_multiple(*count);
871869
let args = PyFuncArgs {
872870
args: args,
873-
kwargs: None,
871+
kwargs: vec![],
874872
};
875873
let func_ref = self.pop_value();
876874

@@ -997,7 +995,7 @@ impl VirtualMachine {
997995
self,
998996
PyFuncArgs {
999997
args: vec![expr.clone()],
1000-
kwargs: None,
998+
kwargs: vec![],
1001999
},
10021000
).unwrap();
10031001
}

0 commit comments

Comments
 (0)