Skip to content

Commit 5eb7754

Browse files
committed
vm.invoke -> obj.call
1 parent ed60687 commit 5eb7754

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

vm/src/protocol/callable.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
function::IntoFuncArgs,
2+
function::{FuncArgs, IntoFuncArgs},
33
types::GenericMethod,
44
{AsObject, PyObject, PyResult, VirtualMachine},
55
};
@@ -14,6 +14,23 @@ impl PyObject {
1414
pub fn is_callable(&self) -> bool {
1515
self.to_callable().is_some()
1616
}
17+
18+
/// PyObject_Call*Arg* series
19+
pub fn call(&self, args: impl IntoFuncArgs, vm: &VirtualMachine) -> PyResult {
20+
self.call_with_args(args.into_args(vm), vm)
21+
}
22+
23+
/// PyObject_Call
24+
pub fn call_with_args(&self, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
25+
vm_trace!("Invoke: {:?} {:?}", callable, args);
26+
let Some(callable) = self.to_callable() else {
27+
return Err(vm.new_type_error(format!(
28+
"'{}' object is not callable",
29+
self.class().name()
30+
)));
31+
};
32+
callable.invoke(args, vm)
33+
}
1734
}
1835

1936
pub struct PyCallable<'a> {

vm/src/vm/vm_object.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::PyMethod;
22
use crate::{
33
builtins::{PyBaseExceptionRef, PyList, PyStr, PyStrInterned},
4-
function::{FuncArgs, IntoFuncArgs},
4+
function::IntoFuncArgs,
55
identifier,
66
object::{AsObject, PyObject, PyObjectRef, PyPayload, PyResult},
77
vm::VirtualMachine,
@@ -151,19 +151,8 @@ impl VirtualMachine {
151151
.invoke(args, self)
152152
}
153153

154-
fn _invoke(&self, obj: &PyObject, args: FuncArgs) -> PyResult {
155-
vm_trace!("Invoke: {:?} {:?}", callable, args);
156-
let Some(callable) = obj.to_callable() else {
157-
return Err(self.new_type_error(format!(
158-
"'{}' object is not callable",
159-
obj.class().name()
160-
)));
161-
};
162-
callable.invoke(args, self)
163-
}
164-
165-
#[inline(always)]
166-
pub fn invoke(&self, func: &impl AsObject, args: impl IntoFuncArgs) -> PyResult {
167-
self._invoke(func.as_object(), args.into_args(self))
154+
// #[deprecated(note = "in favor of `obj.call(args, vm)`")]
155+
pub fn invoke(&self, obj: &impl AsObject, args: impl IntoFuncArgs) -> PyResult {
156+
obj.as_object().call(args, self)
168157
}
169158
}

0 commit comments

Comments
 (0)