forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjmodule.rs
More file actions
31 lines (26 loc) · 768 Bytes
/
objmodule.rs
File metadata and controls
31 lines (26 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::obj::objstr::PyStringRef;
use crate::obj::objtype::PyClassRef;
use crate::pyobject::{PyContext, PyRef, PyResult, PyValue};
use crate::vm::VirtualMachine;
#[derive(Debug)]
pub struct PyModule {
pub name: String,
}
pub type PyModuleRef = PyRef<PyModule>;
impl PyValue for PyModule {
const HAVE_DICT: bool = true;
fn class(vm: &VirtualMachine) -> PyClassRef {
vm.ctx.module_type()
}
}
impl PyModuleRef {
fn init(self, name: PyStringRef, vm: &VirtualMachine) -> PyResult {
vm.set_attr(&self.into_object(), "__name__", name)?;
Ok(vm.get_none())
}
}
pub fn init(context: &PyContext) {
extend_class!(&context, &context.module_type, {
"__init__" => context.new_rustfunc(PyModuleRef::init),
});
}