Properly pass kwargs to metaclass in builtin_build_class

This commit is contained in:
Noah
2020-02-16 15:48:19 -06:00
parent e27fa254fa
commit e682959c9a
2 changed files with 19 additions and 1 deletions

View File

@@ -959,7 +959,10 @@ pub fn builtin_build_class_(
let class = vm.invoke(
metaclass.as_object(),
vec![name_obj, bases, namespace.into_object()],
(
Args::from(vec![name_obj, bases, namespace.into_object()]),
kwargs,
),
)?;
cells.set_item("__class__", class.clone(), vm)?;
Ok(class)

View File

@@ -44,6 +44,16 @@ impl From<PyObjectRef> for PyFuncArgs {
}
}
impl From<(Args, KwArgs)> for PyFuncArgs {
fn from(arg: (Args, KwArgs)) -> Self {
let Args(args) = arg.0;
let KwArgs(kwargs) = arg.1;
PyFuncArgs {
args,
kwargs: kwargs.into_iter().collect(),
}
}
}
impl From<(&Args, &KwArgs)> for PyFuncArgs {
fn from(arg: (&Args, &KwArgs)) -> Self {
let Args(args) = arg.0;
@@ -293,6 +303,11 @@ impl<T> Args<T> {
self.0
}
}
impl<T> From<Vec<T>> for Args<T> {
fn from(v: Vec<T>) -> Self {
Args(v)
}
}
impl<T: PyValue> Args<PyRef<T>> {
pub fn into_tuple(self, vm: &VirtualMachine) -> PyObjectRef {