mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Use ItemProtocol over vm.call_method("__getitem__")
This commit is contained in:
1 parent
20812c61e9
commit
d09488f159
2 files changed
+4
-12
No files matched your search
+2
-10
@@ -2,7 +2,7 @@
|
||||
/// [https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting]
|
||||
use crate::format::get_num_digits;
|
||||
use crate::obj::{objfloat, objint, objstr, objtuple, objtype};
|
||||
use crate::pyobject::{PyObjectRef, PyResult, TryFromObject, TypeProtocol};
|
||||
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult, TryFromObject, TypeProtocol};
|
||||
use crate::vm::VirtualMachine;
|
||||
use num_bigint::{BigInt, Sign};
|
||||
use num_traits::cast::ToPrimitive;
|
||||
@@ -407,14 +407,6 @@ impl CFormatString {
|
||||
vm: &VirtualMachine,
|
||||
values_obj: PyObjectRef,
|
||||
) -> PyResult<String> {
|
||||
fn call_getitem(
|
||||
vm: &VirtualMachine,
|
||||
container: &PyObjectRef,
|
||||
key: &PyObjectRef,
|
||||
) -> PyResult {
|
||||
vm.call_method(container, "__getitem__", vec![key.clone()])
|
||||
}
|
||||
|
||||
fn try_update_quantity_from_tuple(
|
||||
vm: &VirtualMachine,
|
||||
elements: &mut dyn Iterator<Item = PyObjectRef>,
|
||||
@@ -494,7 +486,7 @@ impl CFormatString {
|
||||
let obj: PyObjectRef = match &format_spec.mapping_key {
|
||||
Some(key) => {
|
||||
// TODO: change the KeyError message to match the one in cpython
|
||||
call_getitem(vm, &values, &vm.ctx.new_str(key.to_owned()))?
|
||||
values.get_item(key, vm)?
|
||||
}
|
||||
None => {
|
||||
let mut elements = objtuple::get_value(&values)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::objbyteinner::try_as_byte;
|
||||
use super::objtype::{issubclass, PyClassRef};
|
||||
use crate::pyobject::{
|
||||
PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
};
|
||||
use crate::stdlib::array::PyArray;
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -57,7 +57,7 @@ impl PyMemoryView {
|
||||
|
||||
#[pymethod(name = "__getitem__")]
|
||||
fn getitem(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
vm.call_method(&self.obj_ref, "__getitem__", vec![needle])
|
||||
self.obj_ref.get_item(&needle, vm)
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
|
||||
Reference in new issue
Block a user