Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions crates/vm/src/sliceable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{}'",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obj.class()
)))
} else {
Err(vm.new_type_error(format!(
"{} indices must be integers or slices or classes that override __index__ operator, not '{}'",
Expand Down
Loading