fix str.maketrans 2 and 3 arguments cases

This commit is contained in:
zer0 committed 2019-05-11 23:58:42 +03:00
1 parent 6e05795521
commit 268cb8d217
3 files changed
+4 -4

No files matched your search

+1 -1
View File
@@ -162,7 +162,7 @@ assert "abc".translate({97: '🎅', 98: None, 99: "xd"}) == "🎅xd"
# str.maketrans
assert str.maketrans({"a": "abc", "b": None, "c": 33}) == {97: "abc", 98: None, 99: 33}
assert str.maketrans("hello", "world", "rust") == {103: "w", 101: "o", 108: "l", 111: "d", "r": None, "u": None, "s": None, "t": None}
assert str.maketrans("hello", "world", "rust") == {104: 119, 101: 111, 108: 108, 111: 100, 114: None, 117: None, 115: None, 116: None}
def try_mutate_str():
word = "word"
+2 -2
View File
@@ -884,7 +884,7 @@ impl PyString {
let new_dict = vm.context().new_dict();
if to_str.len(vm) == from_str.len(vm) {
for (c1, c2) in from_str.value.chars().zip(to_str.value.chars()) {
new_dict.set_item(c1.to_string(), vm.new_str(c2.to_string()), vm)?;
new_dict.set_item(c1 as u32, vm.new_int(c2 as u32), vm)?;
}
} else {
return Err(vm.new_value_error(
@@ -893,7 +893,7 @@ impl PyString {
}
if let OptionalArg::Present(none_str) = none_str {
for c in none_str.value.chars() {
new_dict.set_item(c.to_string(), vm.get_none(), vm)?;
new_dict.set_item(c as u32, vm.get_none(), vm)?;
}
}
new_dict.into_pyobject(vm)
+1 -1
View File
@@ -8,4 +8,4 @@ python3 not_impl_gen.py
cd ..
cargo +nightly run -- tests/snippets/whats_left_to_implement.py
cargo run -- tests/snippets/whats_left_to_implement.py