Skip to content

Commit 2a2d0e4

Browse files
committed
Add complex.__rmul__
1 parent 982bbd6 commit 2a2d0e4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

tests/snippets/builtin_complex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
assert complex(2, -3) * complex(-5, 7) == complex(11, 29)
3131
assert complex(2, -3) * 5 == complex(10, -15)
32+
assert 5 * complex(2, -3) == complex(2, -3) * 5
3233

3334
# __neg__
3435

vm/src/obj/objcomplex.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ impl PyComplex {
141141
)
142142
}
143143

144+
#[pymethod(name = "__rmul__")]
145+
fn rmul(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
146+
self.mul(other, vm)
147+
}
148+
144149
#[pymethod(name = "__neg__")]
145150
fn neg(&self, _vm: &VirtualMachine) -> Complex64 {
146151
-self.value

0 commit comments

Comments
 (0)