forked from Rust-related/RustPython
vm.invoke -> obj.call
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
function::IntoFuncArgs,
|
||||
function::{FuncArgs, IntoFuncArgs},
|
||||
types::GenericMethod,
|
||||
{AsObject, PyObject, PyResult, VirtualMachine},
|
||||
};
|
||||
@@ -14,6 +14,23 @@ impl PyObject {
|
||||
pub fn is_callable(&self) -> bool {
|
||||
self.to_callable().is_some()
|
||||
}
|
||||
|
||||
/// PyObject_Call*Arg* series
|
||||
pub fn call(&self, args: impl IntoFuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
self.call_with_args(args.into_args(vm), vm)
|
||||
}
|
||||
|
||||
/// PyObject_Call
|
||||
pub fn call_with_args(&self, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
vm_trace!("Invoke: {:?} {:?}", callable, args);
|
||||
let Some(callable) = self.to_callable() else {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"'{}' object is not callable",
|
||||
self.class().name()
|
||||
)));
|
||||
};
|
||||
callable.invoke(args, vm)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PyCallable<'a> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::PyMethod;
|
||||
use crate::{
|
||||
builtins::{PyBaseExceptionRef, PyList, PyStr, PyStrInterned},
|
||||
function::{FuncArgs, IntoFuncArgs},
|
||||
function::IntoFuncArgs,
|
||||
identifier,
|
||||
object::{AsObject, PyObject, PyObjectRef, PyPayload, PyResult},
|
||||
vm::VirtualMachine,
|
||||
@@ -151,19 +151,8 @@ impl VirtualMachine {
|
||||
.invoke(args, self)
|
||||
}
|
||||
|
||||
fn _invoke(&self, obj: &PyObject, args: FuncArgs) -> PyResult {
|
||||
vm_trace!("Invoke: {:?} {:?}", callable, args);
|
||||
let Some(callable) = obj.to_callable() else {
|
||||
return Err(self.new_type_error(format!(
|
||||
"'{}' object is not callable",
|
||||
obj.class().name()
|
||||
)));
|
||||
};
|
||||
callable.invoke(args, self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn invoke(&self, func: &impl AsObject, args: impl IntoFuncArgs) -> PyResult {
|
||||
self._invoke(func.as_object(), args.into_args(self))
|
||||
// #[deprecated(note = "in favor of `obj.call(args, vm)`")]
|
||||
pub fn invoke(&self, obj: &impl AsObject, args: impl IntoFuncArgs) -> PyResult {
|
||||
obj.as_object().call(args, self)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user