Skip to content

Commit 555f749

Browse files
committed
Use OptionalArg for the builtin function bool
1 parent 56bffd7 commit 555f749

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

vm/src/obj/objbool.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use num_bigint::Sign;
22
use num_traits::Zero;
33

4-
use crate::function::PyFuncArgs;
4+
use crate::function::{OptionalArg, PyFuncArgs};
55
use crate::pyobject::{
66
IdProtocol, IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyResult, TryFromObject,
77
TypeProtocol,
@@ -150,8 +150,7 @@ impl PyBool {
150150
}
151151

152152
#[pyslot]
153-
fn tp_new(vm: &VirtualMachine, mut args: PyFuncArgs) -> PyResult {
154-
let zelf = &args.shift();
153+
fn tp_new(zelf: PyObjectRef, x: OptionalArg<PyObjectRef>, vm: &VirtualMachine) -> PyResult {
155154
if !objtype::isinstance(&zelf, &vm.ctx.type_type()) {
156155
let zelf_typ = zelf.class();
157156
let actual_type = vm.to_pystr(&zelf_typ)?;
@@ -160,18 +159,11 @@ impl PyBool {
160159
actual_type
161160
)));
162161
}
163-
if args.args.len() > 1 {
164-
Err(vm.new_type_error(format!(
165-
"bool expected at most 1 arguments, got {}",
166-
args.args.len()
167-
)))
168-
} else {
169-
let value = match args.take_positional() {
170-
Some(val) => boolval(vm, val.clone())?,
171-
None => false,
172-
};
173-
Ok(vm.new_bool(value))
174-
}
162+
let val = match x {
163+
OptionalArg::Present(val) => boolval(vm, val.clone())?,
164+
OptionalArg::Missing => false,
165+
};
166+
Ok(vm.new_bool(val))
175167
}
176168
}
177169

0 commit comments

Comments
 (0)