Skip to content

Commit 1dceae9

Browse files
ChJRwindelbouwman
authored andcommitted
Add str.__rmod__() method. #190 (#1262)
* Add str.__rmod__ method. * Add tests for str.__rmod__ method. * Improve test for str.__rmod__ method. * Change str.__rmod__ method return value type. * Format with rustfmt. * Remove not required code of str.__rmod__ method. * Improve with clippy.
1 parent 2b02371 commit 1dceae9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

tests/snippets/strings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,6 @@ def try_mutate_str():
293293
assert next(str_iter_reversed) == "1"
294294
assert next(str_iter_reversed, None) == None
295295
assert_raises(StopIteration, lambda: next(str_iter_reversed))
296+
297+
assert str.__rmod__('%i', 30) == NotImplemented
298+
assert_raises(TypeError, lambda: str.__rmod__(30, '%i'))

vm/src/obj/objstr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ impl PyString {
518518
do_cformat(vm, format_string, values.clone())
519519
}
520520

521+
#[pymethod(name = "__rmod__")]
522+
fn rmod(&self, _values: PyObjectRef, vm: &VirtualMachine) -> PyResult {
523+
Ok(vm.ctx.not_implemented())
524+
}
525+
521526
#[pymethod]
522527
fn format(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
523528
if args.args.is_empty() {

0 commit comments

Comments
 (0)