Skip to content

Commit 7b98092

Browse files
committed
Check __bool__() returns only bool value
1 parent adc919f commit 7b98092

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vm/src/obj/objbool.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ pub fn boolval(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<bool> {
2929
// If descriptor returns Error, propagate it further
3030
let method = method_or_err?;
3131
let bool_obj = vm.invoke(&method, PyFuncArgs::default())?;
32+
if !objtype::isinstance(&bool_obj, &vm.ctx.bool_type()) {
33+
return Err(vm.new_type_error(format!(
34+
"__bool__ should return bool, returned type {}",
35+
bool_obj.class().name
36+
)));
37+
}
38+
3239
match bool_obj.payload::<PyInt>() {
3340
Some(int_obj) => !int_obj.as_bigint().is_zero(),
3441
None => {

0 commit comments

Comments
 (0)