(&self, needle: &K, vm: &VirtualMachine)
| 707 | } |
| 708 | |
| 709 | pub fn get_item<K: DictKey + ?Sized>(&self, needle: &K, vm: &VirtualMachine) -> PyResult { |
| 710 | if let Some(dict) = self.downcast_ref_if_exact::<PyDict>(vm) { |
| 711 | return dict.get_item(needle, vm); |
| 712 | } |
| 713 | |
| 714 | let needle = needle.to_pyobject(vm); |
| 715 | |
| 716 | if let Ok(mapping) = self.try_mapping(vm) { |
| 717 | mapping.subscript(&needle, vm) |
| 718 | } else if let Ok(seq) = self.try_sequence(vm) { |
| 719 | let i = needle.key_as_isize(vm)?; |
| 720 | seq.get_item(i, vm) |
| 721 | } else { |
| 722 | if self.class().fast_issubclass(vm.ctx.types.type_type) { |
| 723 | if self.is(vm.ctx.types.type_type) { |
| 724 | return PyGenericAlias::from_args(self.class().to_owned(), needle, vm) |
| 725 | .to_pyresult(vm); |
| 726 | } |
| 727 | |
| 728 | if let Some(class_getitem) = |
| 729 | vm.get_attribute_opt(self.to_owned(), identifier!(vm, __class_getitem__))? |
| 730 | && !vm.is_none(&class_getitem) |
| 731 | { |
| 732 | return class_getitem.call((needle,), vm); |
| 733 | } |
| 734 | return Err(vm.new_type_error(format!( |
| 735 | "type '{}' is not subscriptable", |
| 736 | self.downcast_ref::<PyType>().unwrap().name() |
| 737 | ))); |
| 738 | } |
| 739 | Err(vm.new_type_error(format!("'{}' object is not subscriptable", self.class()))) |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | pub fn set_item<K: DictKey + ?Sized>( |
| 744 | &self, |
nothing calls this directly
no test coverage detected