mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix PyNamespace constructor
This commit is contained in:
1 file changed
+5
-3
@@ -11,6 +11,7 @@ use crate::vm::VirtualMachine;
|
||||
pub struct PyNamespace;
|
||||
|
||||
impl PyValue for PyNamespace {
|
||||
const HAVE_DICT: bool = true;
|
||||
fn class(vm: &VirtualMachine) -> PyClassRef {
|
||||
vm.ctx.namespace_type()
|
||||
}
|
||||
@@ -18,12 +19,13 @@ impl PyValue for PyNamespace {
|
||||
|
||||
#[pyimpl]
|
||||
impl PyNamespace {
|
||||
#[pymethod(name = "__init__")]
|
||||
fn init(zelf: PyRef<Self>, kwargs: KwArgs, vm: &VirtualMachine) -> PyResult<()> {
|
||||
#[pyslot(new)]
|
||||
fn tp_new(cls: PyClassRef, kwargs: KwArgs, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
let zelf = PyNamespace.into_ref_with_type(vm, cls)?;
|
||||
for (name, value) in kwargs.into_iter() {
|
||||
vm.set_attr(zelf.as_object(), name, value)?;
|
||||
}
|
||||
Ok(())
|
||||
Ok(zelf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user