forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarnings.rs
More file actions
37 lines (33 loc) · 986 Bytes
/
warnings.rs
File metadata and controls
37 lines (33 loc) · 986 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
32
33
34
35
36
37
use crate::function::OptionalArg;
use crate::obj::objstr::PyStringRef;
use crate::pyobject::PyObjectRef;
use crate::vm::VirtualMachine;
#[derive(FromArgs)]
struct WarnArgs {
#[pyarg(positional_only, optional = false)]
message: PyStringRef,
#[pyarg(positional_or_keyword, optional = true)]
category: OptionalArg<PyObjectRef>,
#[pyarg(positional_or_keyword, optional = true)]
stacklevel: OptionalArg<u32>,
}
fn warnings_warn(args: WarnArgs, _vm: &VirtualMachine) {
// TODO: Implement correctly
let level = match args.stacklevel {
OptionalArg::Present(l) => l,
OptionalArg::Missing => 1,
};
eprintln!(
"Warning: {} , category: {:?}, level: {}",
args.message.as_str(),
args.category,
level
)
}
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let ctx = &vm.ctx;
let module = py_module!(vm, "_warnings", {
"warn" => ctx.new_rustfunc(warnings_warn),
});
module
}