(&self, needle: &PyObject, vm: &VirtualMachine)
| 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 { |
nothing calls this directly
no test coverage detected