1+ use crate :: call:: PyCallArgs ;
12use crate :: class:: basic:: CompareOp ;
23use crate :: conversion:: { AsPyPointer , FromPyObjectBound , IntoPyObject } ;
34use crate :: err:: { DowncastError , DowncastIntoError , PyErr , PyResult } ;
@@ -10,7 +11,7 @@ use crate::py_result_ext::PyResultExt;
1011use crate :: type_object:: { PyTypeCheck , PyTypeInfo } ;
1112#[ cfg( not( any( PyPy , GraalPy ) ) ) ]
1213use crate :: types:: PySuper ;
13- use crate :: types:: { PyDict , PyIterator , PyList , PyString , PyTuple , PyType } ;
14+ use crate :: types:: { PyDict , PyIterator , PyList , PyString , PyType } ;
1415use crate :: { err, ffi, Borrowed , BoundObject , IntoPyObjectExt , Python } ;
1516use std:: cell:: UnsafeCell ;
1617use std:: cmp:: Ordering ;
@@ -436,7 +437,7 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed {
436437 /// ```
437438 fn call < A > ( & self , args : A , kwargs : Option < & Bound < ' py , PyDict > > ) -> PyResult < Bound < ' py , PyAny > >
438439 where
439- A : IntoPyObject < ' py , Target = PyTuple > ;
440+ A : PyCallArgs < ' py > ;
440441
441442 /// Calls the object without arguments.
442443 ///
@@ -491,7 +492,7 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed {
491492 /// ```
492493 fn call1 < A > ( & self , args : A ) -> PyResult < Bound < ' py , PyAny > >
493494 where
494- A : IntoPyObject < ' py , Target = PyTuple > ;
495+ A : PyCallArgs < ' py > ;
495496
496497 /// Calls a method on the object.
497498 ///
@@ -538,7 +539,7 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed {
538539 ) -> PyResult < Bound < ' py , PyAny > >
539540 where
540541 N : IntoPyObject < ' py , Target = PyString > ,
541- A : IntoPyObject < ' py , Target = PyTuple > ;
542+ A : PyCallArgs < ' py > ;
542543
543544 /// Calls a method on the object without arguments.
544545 ///
@@ -614,7 +615,7 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed {
614615 fn call_method1 < N , A > ( & self , name : N , args : A ) -> PyResult < Bound < ' py , PyAny > >
615616 where
616617 N : IntoPyObject < ' py , Target = PyString > ,
617- A : IntoPyObject < ' py , Target = PyTuple > ;
618+ A : PyCallArgs < ' py > ;
618619
619620 /// Returns whether the object is considered to be true.
620621 ///
@@ -1209,25 +1210,17 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
12091210
12101211 fn call < A > ( & self , args : A , kwargs : Option < & Bound < ' py , PyDict > > ) -> PyResult < Bound < ' py , PyAny > >
12111212 where
1212- A : IntoPyObject < ' py , Target = PyTuple > ,
1213+ A : PyCallArgs < ' py > ,
12131214 {
1214- fn inner < ' py > (
1215- any : & Bound < ' py , PyAny > ,
1216- args : Borrowed < ' _ , ' py , PyTuple > ,
1217- kwargs : Option < & Bound < ' py , PyDict > > ,
1218- ) -> PyResult < Bound < ' py , PyAny > > {
1219- unsafe {
1220- ffi:: PyObject_Call (
1221- any. as_ptr ( ) ,
1222- args. as_ptr ( ) ,
1223- kwargs. map_or ( std:: ptr:: null_mut ( ) , |dict| dict. as_ptr ( ) ) ,
1224- )
1225- . assume_owned_or_err ( any. py ( ) )
1226- }
1215+ if let Some ( kwargs) = kwargs {
1216+ args. call (
1217+ self . as_borrowed ( ) ,
1218+ kwargs. as_borrowed ( ) ,
1219+ crate :: call:: private:: Token ,
1220+ )
1221+ } else {
1222+ args. call_positional ( self . as_borrowed ( ) , crate :: call:: private:: Token )
12271223 }
1228-
1229- let py = self . py ( ) ;
1230- inner ( self , args. into_pyobject_or_pyerr ( py) ?. as_borrowed ( ) , kwargs)
12311224 }
12321225
12331226 #[ inline]
@@ -1237,9 +1230,9 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
12371230
12381231 fn call1 < A > ( & self , args : A ) -> PyResult < Bound < ' py , PyAny > >
12391232 where
1240- A : IntoPyObject < ' py , Target = PyTuple > ,
1233+ A : PyCallArgs < ' py > ,
12411234 {
1242- self . call ( args , None )
1235+ args . call_positional ( self . as_borrowed ( ) , crate :: call :: private :: Token )
12431236 }
12441237
12451238 #[ inline]
@@ -1251,10 +1244,14 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
12511244 ) -> PyResult < Bound < ' py , PyAny > >
12521245 where
12531246 N : IntoPyObject < ' py , Target = PyString > ,
1254- A : IntoPyObject < ' py , Target = PyTuple > ,
1247+ A : PyCallArgs < ' py > ,
12551248 {
1256- self . getattr ( name)
1257- . and_then ( |method| method. call ( args, kwargs) )
1249+ if kwargs. is_none ( ) {
1250+ self . call_method1 ( name, args)
1251+ } else {
1252+ self . getattr ( name)
1253+ . and_then ( |method| method. call ( args, kwargs) )
1254+ }
12581255 }
12591256
12601257 #[ inline]
@@ -1273,9 +1270,14 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
12731270 fn call_method1 < N , A > ( & self , name : N , args : A ) -> PyResult < Bound < ' py , PyAny > >
12741271 where
12751272 N : IntoPyObject < ' py , Target = PyString > ,
1276- A : IntoPyObject < ' py , Target = PyTuple > ,
1273+ A : PyCallArgs < ' py > ,
12771274 {
1278- self . call_method ( name, args, None )
1275+ let name = name. into_pyobject_or_pyerr ( self . py ( ) ) ?;
1276+ args. call_method_positional (
1277+ self . as_borrowed ( ) ,
1278+ name. as_borrowed ( ) ,
1279+ crate :: call:: private:: Token ,
1280+ )
12791281 }
12801282
12811283 fn is_truthy ( & self ) -> PyResult < bool > {
0 commit comments