bool.real

This commit is contained in:
Jeong YunWon
2019-08-21 01:24:38 +09:00
parent 2dab55864c
commit 0327428aa5
3 changed files with 8 additions and 3 deletions

View File

@@ -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

View File

@@ -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()),
});
}

View File

@@ -681,8 +681,8 @@ impl PyInt {
Ok(PyBytes::new(bytes))
}
#[pyproperty]
fn real(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
zelf
fn real(&self, vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.new_int(self.value.clone())
}
#[pyproperty]