Skip to content

Commit d60dfd2

Browse files
committed
Test __bool__ and fix it.
1 parent d5668c3 commit d60dfd2

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

tests/snippets/bools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@
2222

2323
if not object():
2424
raise BaseException
25+
26+
class Falsey:
27+
def __bool__(self):
28+
return False
29+
30+
assert not Falsey()

vm/src/objbool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::objtype;
22
use super::pyobject::{
3-
AttributeProtocol, PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
3+
AttributeProtocol, PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult,
44
};
55
use super::vm::VirtualMachine;
66

@@ -14,7 +14,7 @@ pub fn boolval(vm: &mut VirtualMachine, obj: PyObjectRef) -> Result<bool, PyObje
1414
PyObjectKind::Dict { ref elements } => !elements.is_empty(),
1515
PyObjectKind::String { ref value } => !value.is_empty(),
1616
_ => {
17-
let f = objtype::get_attribute(vm, obj.typ(), &String::from("__bool__"))?;
17+
let f = objtype::get_attribute(vm, obj.clone(), &String::from("__bool__"))?;
1818
match vm.invoke(f, PyFuncArgs::new()) {
1919
Ok(result) => match result.borrow().kind {
2020
PyObjectKind::Boolean { value } => value,

0 commit comments

Comments
 (0)