From d84b8b52a5897b1e8fa2c2a03f43198c443447cd Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 25 Apr 2019 10:37:59 +1200 Subject: [PATCH] Fix the tuple from rpartition being in wrong order when sub isn't contained within the string --- tests/snippets/strings.py | 2 ++ vm/src/obj/objstr.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/snippets/strings.py b/tests/snippets/strings.py index adcc106bb..86fbe69f3 100644 --- a/tests/snippets/strings.py +++ b/tests/snippets/strings.py @@ -132,7 +132,9 @@ assert 'abc\t12345\txyz'.expandtabs() == 'abc 12345 xyz' assert '-'.join(['1', '2', '3']) == '1-2-3' assert 'HALLO'.isupper() assert "hello, my name is".partition("my ") == ('hello, ', 'my ', 'name is') +assert "hello".partition("is") == ('hello', '', '') assert "hello, my name is".rpartition("is") == ('hello, my name ', 'is', '') +assert "hello".rpartition("is") == ('', '', 'hello') assert not ''.isdecimal() assert '123'.isdecimal() assert not '\u00B2'.isdecimal() diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index b52a91409..dd610f4c8 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -635,9 +635,9 @@ impl PyString { new_tup.swap(0, 1); // so it's in the right order new_tup.insert(1, vm.ctx.new_str(sub.clone())); } else { + new_tup.push(vm.ctx.new_str("".to_string())); + new_tup.push(vm.ctx.new_str("".to_string())); new_tup.push(vm.ctx.new_str(value.clone())); - new_tup.push(vm.ctx.new_str("".to_string())); - new_tup.push(vm.ctx.new_str("".to_string())); } vm.ctx.new_tuple(new_tup) }