Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bool_wrapper
  • Loading branch information
youknowone committed Dec 25, 2025
commit 97c49498253eee663263f52eb2c3d1c64107bb6b
1 change: 0 additions & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10496,7 +10496,6 @@ class CustomerModel(ModelBase, init=False):


class NoDefaultTests(BaseTestCase):
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
s = pickle.dumps(NoDefault, proto)
Expand Down
15 changes: 15 additions & 0 deletions crates/vm/src/types/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,18 @@ fn iter_wrapper(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
vm.call_special_method(&zelf, identifier!(vm, __iter__), ())
}

fn bool_wrapper(num: PyNumber<'_>, vm: &VirtualMachine) -> PyResult<bool> {
let result = vm.call_special_method(num.obj(), identifier!(vm, __bool__), ())?;
// __bool__ must return exactly bool, not int subclass
if !result.class().is(vm.ctx.types.bool_type) {
return Err(vm.new_type_error(format!(
"__bool__ should return bool, returned {}",
result.class().name()
)));
}
Ok(crate::builtins::bool_::get_value(&result))
}

// PyObject_SelfIter in CPython
const fn self_iter(zelf: PyObjectRef, _vm: &VirtualMachine) -> PyResult {
Ok(zelf)
Expand Down Expand Up @@ -656,6 +668,9 @@ impl PyType {
_ if name == identifier!(ctx, __del__) => {
toggle_slot!(del, del_wrapper);
}
_ if name == identifier!(ctx, __bool__) => {
toggle_sub_slot!(as_number, boolean, bool_wrapper);
}
_ if name == identifier!(ctx, __int__) => {
toggle_sub_slot!(as_number, int, number_unary_op_wrapper!(__int__));
}
Expand Down