mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Use OptionalArg for the builtin function bool
This commit is contained in:
1 parent
56bffd795b
commit
555f749c74
1 file changed
+7
-15
+7
-15
@@ -1,7 +1,7 @@
|
||||
use num_bigint::Sign;
|
||||
use num_traits::Zero;
|
||||
|
||||
use crate::function::PyFuncArgs;
|
||||
use crate::function::{OptionalArg, PyFuncArgs};
|
||||
use crate::pyobject::{
|
||||
IdProtocol, IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyResult, TryFromObject,
|
||||
TypeProtocol,
|
||||
@@ -150,8 +150,7 @@ impl PyBool {
|
||||
}
|
||||
|
||||
#[pyslot]
|
||||
fn tp_new(vm: &VirtualMachine, mut args: PyFuncArgs) -> PyResult {
|
||||
let zelf = &args.shift();
|
||||
fn tp_new(zelf: PyObjectRef, x: OptionalArg<PyObjectRef>, vm: &VirtualMachine) -> PyResult {
|
||||
if !objtype::isinstance(&zelf, &vm.ctx.type_type()) {
|
||||
let zelf_typ = zelf.class();
|
||||
let actual_type = vm.to_pystr(&zelf_typ)?;
|
||||
@@ -160,18 +159,11 @@ impl PyBool {
|
||||
actual_type
|
||||
)));
|
||||
}
|
||||
if args.args.len() > 1 {
|
||||
Err(vm.new_type_error(format!(
|
||||
"bool expected at most 1 arguments, got {}",
|
||||
args.args.len()
|
||||
)))
|
||||
} else {
|
||||
let value = match args.take_positional() {
|
||||
Some(val) => boolval(vm, val.clone())?,
|
||||
None => false,
|
||||
};
|
||||
Ok(vm.new_bool(value))
|
||||
}
|
||||
let val = match x {
|
||||
OptionalArg::Present(val) => boolval(vm, val.clone())?,
|
||||
OptionalArg::Missing => false,
|
||||
};
|
||||
Ok(vm.new_bool(val))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user