Skip to content

Commit 0327428

Browse files
committed
bool.real
1 parent 2dab558 commit 0327428

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

tests/snippets/bools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def __bool__(self):
8080
assert False.__rxor__(0) is not False
8181
assert False.__rxor__(False) is False
8282

83+
assert True.real == 1
84+
assert True.imag == 0
85+
assert type(True.real) is int
86+
assert type(True.imag) is int
87+
8388
# Check work for sequence and map
8489
assert bool({}) is False
8590
assert bool([]) is False

vm/src/obj/objbool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The class bool is a subclass of the class int, and cannot be subclassed.";
7777
"__rand__" => context.new_rustfunc(bool_rand),
7878
"__xor__" => context.new_rustfunc(bool_xor),
7979
"__rxor__" => context.new_rustfunc(bool_rxor),
80-
"__doc__" => context.new_str(bool_doc.to_string())
80+
"__doc__" => context.new_str(bool_doc.to_string()),
8181
});
8282
}
8383

vm/src/obj/objint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ impl PyInt {
681681
Ok(PyBytes::new(bytes))
682682
}
683683
#[pyproperty]
684-
fn real(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
685-
zelf
684+
fn real(&self, vm: &VirtualMachine) -> PyObjectRef {
685+
vm.ctx.new_int(self.value.clone())
686686
}
687687

688688
#[pyproperty]

0 commit comments

Comments
 (0)