Skip to content

Commit 18a49d1

Browse files
Merge pull request RustPython#1077 from hannut91/add-tuple-rmul
Add tuple.__rmul__
2 parents 32be3bc + 91d901a commit 18a49d1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

tests/snippets/tuple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
assert x + y == (1, 2, 1)
1010

1111
assert x * 3 == (1, 2, 1, 2, 1, 2)
12-
# assert 3 * x == (1, 2, 1, 2, 1, 2)
12+
assert 3 * x == (1, 2, 1, 2, 1, 2)
1313
assert x * 0 == ()
1414
assert x * -1 == () # integers less than zero treated as 0
1515

vm/src/obj/objtuple.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ impl PyTupleRef {
168168
vm.ctx.new_tuple(new_elements)
169169
}
170170

171+
fn rmul(self, counter: isize, vm: &VirtualMachine) -> PyObjectRef {
172+
let new_elements = seq_mul(&self.elements, counter);
173+
vm.ctx.new_tuple(new_elements)
174+
}
175+
171176
fn getitem(self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult {
172177
get_item(vm, self.as_object(), &self.elements, needle.clone())
173178
}
@@ -263,6 +268,7 @@ If the argument is a tuple, the return value is the same object.";
263268
"__len__" => context.new_rustfunc(PyTupleRef::len),
264269
"__new__" => context.new_rustfunc(tuple_new),
265270
"__mul__" => context.new_rustfunc(PyTupleRef::mul),
271+
"__rmul__" => context.new_rustfunc(PyTupleRef::rmul),
266272
"__repr__" => context.new_rustfunc(PyTupleRef::repr),
267273
"count" => context.new_rustfunc(PyTupleRef::count),
268274
"__lt__" => context.new_rustfunc(PyTupleRef::lt),

0 commit comments

Comments
 (0)