diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 0c159e02fb9..66e6d78940b 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -1301,7 +1301,6 @@ def test___contains__(self): self.checkequal(False, 'asd', '__contains__', 'asdf') self.checkequal(False, '', '__contains__', 'asdf') - @unittest.expectedFailure # TODO: RUSTPYTHON def test_subscript(self): self.checkequal('a', 'abc', '__getitem__', 0) self.checkequal('c', 'abc', '__getitem__', -1) diff --git a/crates/vm/src/sliceable.rs b/crates/vm/src/sliceable.rs index b0f4c7808ff..635aac292a9 100644 --- a/crates/vm/src/sliceable.rs +++ b/crates/vm/src/sliceable.rs @@ -275,6 +275,12 @@ impl SequenceIndex { i?.try_to_primitive(vm) .map_err(|_| vm.new_index_error("cannot fit 'int' into an index-sized integer")) .map(Self::Int) + } else if type_name == "str" { + // CPython's unicode_subscript raises a distinct message here. + Err(vm.new_type_error(format!( + "string indices must be integers, not '{}'", + obj.class() + ))) } else { Err(vm.new_type_error(format!( "{} indices must be integers or slices or classes that override __index__ operator, not '{}'",