From 0327428aa5e7fa259dc2a30e2c4eda51fe83a16e Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 21 Aug 2019 01:24:38 +0900 Subject: [PATCH] bool.real --- tests/snippets/bools.py | 5 +++++ vm/src/obj/objbool.rs | 2 +- vm/src/obj/objint.rs | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/snippets/bools.py b/tests/snippets/bools.py index c33fcff0fc..e9d41c5d58 100644 --- a/tests/snippets/bools.py +++ b/tests/snippets/bools.py @@ -80,6 +80,11 @@ assert False.__xor__(False) is False assert False.__rxor__(0) is not False assert False.__rxor__(False) is False +assert True.real == 1 +assert True.imag == 0 +assert type(True.real) is int +assert type(True.imag) is int + # Check work for sequence and map assert bool({}) is False assert bool([]) is False diff --git a/vm/src/obj/objbool.rs b/vm/src/obj/objbool.rs index 19d95889f8..91d47c6266 100644 --- a/vm/src/obj/objbool.rs +++ b/vm/src/obj/objbool.rs @@ -77,7 +77,7 @@ The class bool is a subclass of the class int, and cannot be subclassed."; "__rand__" => context.new_rustfunc(bool_rand), "__xor__" => context.new_rustfunc(bool_xor), "__rxor__" => context.new_rustfunc(bool_rxor), - "__doc__" => context.new_str(bool_doc.to_string()) + "__doc__" => context.new_str(bool_doc.to_string()), }); } diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 478671257c..296f458669 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -681,8 +681,8 @@ impl PyInt { Ok(PyBytes::new(bytes)) } #[pyproperty] - fn real(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { - zelf + fn real(&self, vm: &VirtualMachine) -> PyObjectRef { + vm.ctx.new_int(self.value.clone()) } #[pyproperty]