Skip to content

Commit 7c54dc8

Browse files
committed
Fix bool.from_bytes
1 parent 1e79d06 commit 7c54dc8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Lib/test/test_bool.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ def __len__(self):
326326
return -1
327327
self.assertRaises(ValueError, bool, Eggs())
328328

329-
# TODO: RUSTPYTHON
330-
@unittest.expectedFailure
331329
def test_from_bytes(self):
332330
self.assertIs(bool.from_bytes(b'\x00'*8, 'big'), False)
333331
self.assertIs(bool.from_bytes(b'abcd', 'little'), True)

vm/src/obj/objint.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ impl PyInt {
233233
{
234234
if cls.is(&vm.ctx.types.int_type) {
235235
Ok(vm.ctx.new_int(value).downcast().unwrap())
236+
} else if cls.is(&vm.ctx.types.bool_type) {
237+
Ok(vm
238+
.ctx
239+
.new_bool(!value.into().eq(&BigInt::zero()))
240+
.downcast()
241+
.unwrap())
236242
} else {
237243
PyInt::from(value).into_ref_with_type(vm, cls)
238244
}

0 commit comments

Comments
 (0)