mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
add __rand__ __ror__
This commit is contained in:
@@ -38,6 +38,20 @@ assert int(0).__invert__() == -1
|
||||
assert int(-3).__invert__() == 2
|
||||
assert int(4).__invert__() == -5
|
||||
|
||||
assert int(0).__ror__(0) == 0
|
||||
assert int(1).__ror__(0) == 1
|
||||
assert int(0).__ror__(1) == 1
|
||||
assert int(1).__ror__(1) == 1
|
||||
assert int(3).__ror__(-3) == -1
|
||||
assert int(3).__ror__(4) == 7
|
||||
|
||||
assert int(0).__rand__(0) == 0
|
||||
assert int(1).__rand__(0) == 0
|
||||
assert int(0).__rand__(1) == 0
|
||||
assert int(1).__rand__(1) == 1
|
||||
assert int(3).__rand__(-3) == 1
|
||||
assert int(3).__rand__(4) == 0
|
||||
|
||||
assert int(0).__rxor__(0) == 0
|
||||
assert int(1).__rxor__(0) == 1
|
||||
assert int(0).__rxor__(1) == 1
|
||||
|
||||
@@ -368,6 +368,11 @@ impl PyInt {
|
||||
}
|
||||
}
|
||||
|
||||
#[pymethod(name = "__ror__")]
|
||||
fn ror(&self,other: PyObjectRef,vm: &VirtualMachine) -> PyObjectRef{
|
||||
self.or(other,vm)
|
||||
}
|
||||
|
||||
#[pymethod(name = "__and__")]
|
||||
pub fn and(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
if objtype::isinstance(&other, &vm.ctx.int_type()) {
|
||||
@@ -377,6 +382,11 @@ impl PyInt {
|
||||
vm.ctx.not_implemented()
|
||||
}
|
||||
}
|
||||
|
||||
#[pymethod(name = "__rand__")]
|
||||
fn rand(&self, other: PyObjectRef,vm: &VirtualMachine) -> PyObjectRef{
|
||||
self.and(other,vm)
|
||||
}
|
||||
|
||||
#[pymethod(name = "__pow__")]
|
||||
fn pow(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
|
||||
Reference in New Issue
Block a user