MCPcopy Index your code
hub / github.com/RustPython/RustPython / subscript

Method subscript

crates/stdlib/src/_sqlite3.rs:2220–2244  ·  view source on GitHub ↗
(&self, needle: &PyObject, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2218 }
2219
2220 fn subscript(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult {
2221 if let Some(i) = needle.downcast_ref::<PyInt>() {
2222 let i = i.try_to_primitive::<isize>(vm)?;
2223 self.data.getitem_by_index(vm, i)
2224 } else if let Some(name) = needle.downcast_ref::<PyStr>() {
2225 for (obj, i) in self.description.iter().zip(0..) {
2226 let obj = &obj.downcast_ref::<PyTuple>().unwrap().as_slice()[0];
2227 let Some(obj) = obj.downcast_ref::<PyStr>() else {
2228 break;
2229 };
2230 let a_iter = name.expect_str().chars().flat_map(|x| x.to_uppercase());
2231 let b_iter = obj.expect_str().chars().flat_map(|x| x.to_uppercase());
2232
2233 if a_iter.eq(b_iter) {
2234 return self.data.getitem_by_index(vm, i);
2235 }
2236 }
2237 Err(vm.new_index_error("No item with that key"))
2238 } else if let Some(slice) = needle.downcast_ref::<PySlice>() {
2239 let list = self.data.getitem_by_slice(vm, slice.to_saturated(vm)?)?;
2240 Ok(vm.ctx.new_tuple(list).into())
2241 } else {
2242 Err(vm.new_index_error("Index must be int or string"))
2243 }
2244 }
2245 }
2246
2247 impl Constructor for Row {

Callers

nothing calls this directly

Calls 15

charsMethod · 0.80
expect_strMethod · 0.80
to_uppercaseMethod · 0.80
to_saturatedMethod · 0.80
try_index_optMethod · 0.80
read_singleMethod · 0.80
adjust_indicesMethod · 0.80
as_mut_ptrMethod · 0.80
set_lenMethod · 0.80
ErrClass · 0.50
getitem_by_indexMethod · 0.45

Tested by

no test coverage detected