forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjnone.rs
More file actions
28 lines (24 loc) · 989 Bytes
/
objnone.rs
File metadata and controls
28 lines (24 loc) · 989 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
use crate::pyobject::{PyContext, PyFuncArgs, PyResult, TypeProtocol};
use crate::vm::VirtualMachine;
pub fn init(context: &PyContext) {
let none_type = &context.none.typ();
context.set_attr(&none_type, "__new__", context.new_rustfunc(none_new));
context.set_attr(&none_type, "__repr__", context.new_rustfunc(none_repr));
context.set_attr(&none_type, "__bool__", context.new_rustfunc(none_bool));
}
fn none_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(
vm,
args,
required = [(_zelf, Some(vm.ctx.type_type.clone()))]
);
Ok(vm.get_none())
}
fn none_repr(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(_zelf, Some(vm.ctx.none().typ()))]);
Ok(vm.ctx.new_str("None".to_string()))
}
fn none_bool(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(_zelf, Some(vm.ctx.none().typ()))]);
Ok(vm.ctx.new_bool(false))
}