Skip to content

Commit b9019d8

Browse files
committed
use PyCallArgs for Py::call and friends
1 parent 8fa2d60 commit b9019d8

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

src/instance.rs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
use crate::call::PyCallArgs;
12
use crate::conversion::IntoPyObject;
23
use crate::err::{self, PyErr, PyResult};
34
use crate::impl_::pycell::PyClassObject;
45
use crate::internal_tricks::ptr_from_ref;
56
use crate::pycell::{PyBorrowError, PyBorrowMutError};
67
use crate::pyclass::boolean_struct::{False, True};
78
use crate::types::{any::PyAnyMethods, string::PyStringMethods, typeobject::PyTypeMethods};
8-
use crate::types::{DerefToPyAny, PyDict, PyString, PyTuple};
9+
use crate::types::{DerefToPyAny, PyDict, PyString};
910
use crate::{
1011
ffi, DowncastError, FromPyObject, PyAny, PyClass, PyClassInitializer, PyRef, PyRefMut,
1112
PyTypeInfo, Python,
@@ -1490,30 +1491,19 @@ impl<T> Py<T> {
14901491
kwargs: Option<&Bound<'py, PyDict>>,
14911492
) -> PyResult<PyObject>
14921493
where
1493-
A: IntoPyObject<'py, Target = PyTuple>,
1494+
A: PyCallArgs<'py>,
14941495
{
1495-
self.bind(py)
1496-
.as_any()
1497-
.call(
1498-
// FIXME(icxolu): remove explicit args conversion
1499-
args.into_pyobject(py).map_err(Into::into)?.into_bound(),
1500-
kwargs,
1501-
)
1502-
.map(Bound::unbind)
1496+
self.bind(py).as_any().call(args, kwargs).map(Bound::unbind)
15031497
}
15041498

15051499
/// Calls the object with only positional arguments.
15061500
///
15071501
/// This is equivalent to the Python expression `self(*args)`.
1508-
pub fn call1<'py, N>(&self, py: Python<'py>, args: N) -> PyResult<PyObject>
1502+
pub fn call1<'py, A>(&self, py: Python<'py>, args: A) -> PyResult<PyObject>
15091503
where
1510-
N: IntoPyObject<'py, Target = PyTuple>,
1504+
A: PyCallArgs<'py>,
15111505
{
1512-
self.bind(py)
1513-
.as_any()
1514-
// FIXME(icxolu): remove explicit args conversion
1515-
.call1(args.into_pyobject(py).map_err(Into::into)?.into_bound())
1516-
.map(Bound::unbind)
1506+
self.bind(py).as_any().call1(args).map(Bound::unbind)
15171507
}
15181508

15191509
/// Calls the object without arguments.
@@ -1538,16 +1528,11 @@ impl<T> Py<T> {
15381528
) -> PyResult<PyObject>
15391529
where
15401530
N: IntoPyObject<'py, Target = PyString>,
1541-
A: IntoPyObject<'py, Target = PyTuple>,
1531+
A: PyCallArgs<'py>,
15421532
{
15431533
self.bind(py)
15441534
.as_any()
1545-
.call_method(
1546-
name,
1547-
// FIXME(icxolu): remove explicit args conversion
1548-
args.into_pyobject(py).map_err(Into::into)?.into_bound(),
1549-
kwargs,
1550-
)
1535+
.call_method(name, args, kwargs)
15511536
.map(Bound::unbind)
15521537
}
15531538

@@ -1560,15 +1545,11 @@ impl<T> Py<T> {
15601545
pub fn call_method1<'py, N, A>(&self, py: Python<'py>, name: N, args: A) -> PyResult<PyObject>
15611546
where
15621547
N: IntoPyObject<'py, Target = PyString>,
1563-
A: IntoPyObject<'py, Target = PyTuple>,
1548+
A: PyCallArgs<'py>,
15641549
{
15651550
self.bind(py)
15661551
.as_any()
1567-
.call_method1(
1568-
name,
1569-
// FIXME(icxolu): remove explicit args conversion
1570-
args.into_pyobject(py).map_err(Into::into)?.into_bound(),
1571-
)
1552+
.call_method1(name, args)
15721553
.map(Bound::unbind)
15731554
}
15741555

0 commit comments

Comments
 (0)