diff --git a/src/instance.rs b/src/instance.rs index 0037abb8..780d35fa 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -580,12 +580,10 @@ impl Py { /// This is equivalent to the Python expression `self()`. pub fn call0(&self, py: Python) -> PyResult { cfg_if::cfg_if! { - // TODO: Use PyObject_CallNoArgs instead after https://bugs.python.org/issue42415. - // Once the issue is resolved, we can enable this optimization for limited API. - if #[cfg(all(Py_3_9, not(Py_LIMITED_API)))] { + if #[cfg(Py_3_9)] { // Optimized path on python 3.9+ unsafe { - PyObject::from_owned_ptr_or_err(py, ffi::_PyObject_CallNoArg(self.as_ptr())) + PyObject::from_owned_ptr_or_err(py, ffi::PyObject_CallNoArgs(self.as_ptr())) } } else { self.call(py, (), None) @@ -923,7 +921,23 @@ impl PyObject { mod tests { use super::{Py, PyObject}; use crate::types::PyDict; - use crate::Python; + use crate::{Python, ToPyObject}; + + #[test] + fn test_call0() { + Python::with_gil(|py| { + let obj = py.get_type::().to_object(py); + assert_eq!( + obj.call0(py) + .unwrap() + .as_ref(py) + .repr() + .unwrap() + .to_string_lossy(), + "{}" + ); + }) + } #[test] fn test_call_for_non_existing_method() { diff --git a/src/types/any.rs b/src/types/any.rs index 0206cd46..b54aa540 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -333,12 +333,10 @@ impl PyAny { /// This is equivalent to the Python expression `help()`. pub fn call0(&self) -> PyResult<&PyAny> { cfg_if::cfg_if! { - // TODO: Use PyObject_CallNoArgs instead after https://bugs.python.org/issue42415. - // Once the issue is resolved, we can enable this optimization for limited API. - if #[cfg(all(Py_3_9, not(Py_LIMITED_API)))] { + if #[cfg(Py_3_9)] { // Optimized path on python 3.9+ unsafe { - self.py().from_owned_ptr_or_err(ffi::_PyObject_CallNoArg(self.as_ptr())) + self.py().from_owned_ptr_or_err(ffi::PyObject_CallNoArgs(self.as_ptr())) } } else { self.call((), None)