mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Add .conjugate() method to int type
Also add tests for for the int type, and a commented out one for the bool type.
This commit is contained in:
@@ -45,6 +45,8 @@ a = complex(2, 4)
|
||||
assert type(a) is complex
|
||||
assert type(a + a) is complex
|
||||
|
||||
a = 1
|
||||
assert a.conjugate() == a
|
||||
|
||||
a = 12345
|
||||
|
||||
|
||||
@@ -46,3 +46,4 @@ assert True + True == 2
|
||||
assert False * 7 == 0
|
||||
assert True > 0
|
||||
assert int(True) == 1
|
||||
#assert True.conjugate() == 1
|
||||
|
||||
@@ -489,6 +489,11 @@ fn int_bit_length(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
Ok(vm.ctx.new_int(bits.to_bigint().unwrap()))
|
||||
}
|
||||
|
||||
fn int_conjugate(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(i, Some(vm.ctx.int_type()))]);
|
||||
Ok(i.clone())
|
||||
}
|
||||
|
||||
pub fn init(context: &PyContext) {
|
||||
let ref int_type = context.int_type;
|
||||
context.set_attr(&int_type, "__eq__", context.new_rustfunc(int_eq));
|
||||
@@ -526,4 +531,5 @@ pub fn init(context: &PyContext) {
|
||||
"bit_length",
|
||||
context.new_rustfunc(int_bit_length),
|
||||
);
|
||||
context.set_attr(&int_type, "conjugate", context.new_rustfunc(int_conjugate));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user