diff --git a/src/types/any.rs b/src/types/any.rs index 2e8a518fad4..b8e8c03ad06 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -2193,7 +2193,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> { #[cfg(not(PyPy))] fn py_super(&self) -> PyResult> { - PySuper::new2(Bound::borrowed_from_gil_ref(&self.get_type()), self) + PySuper::new_bound(Bound::borrowed_from_gil_ref(&self.get_type()), self) } } diff --git a/src/types/pysuper.rs b/src/types/pysuper.rs index 5cf05a36a4d..d14670987b5 100644 --- a/src/types/pysuper.rs +++ b/src/types/pysuper.rs @@ -16,6 +16,19 @@ pyobject_native_type_core!( ); impl PySuper { + /// Deprecated form of `PySuper::new_bound`. + #[deprecated( + since = "0.21.0", + note = "`PySuper::new` will be replaced by `PySuper::new_bound` in a future PyO3 version" + )] + pub fn new<'py>(ty: &'py PyType, obj: &'py PyAny) -> PyResult<&'py PySuper> { + Self::new_bound( + Bound::borrowed_from_gil_ref(&ty), + Bound::borrowed_from_gil_ref(&obj), + ) + .map(Bound::into_gil_ref) + } + /// Constructs a new super object. More read about super object: [docs](https://docs.python.org/3/library/functions.html#super) /// /// # Examples @@ -56,15 +69,7 @@ impl PySuper { /// } /// } /// ``` - pub fn new<'py>(ty: &'py PyType, obj: &'py PyAny) -> PyResult<&'py PySuper> { - Self::new2( - Bound::borrowed_from_gil_ref(&ty), - Bound::borrowed_from_gil_ref(&obj), - ) - .map(Bound::into_gil_ref) - } - - pub(crate) fn new2<'py>( + pub fn new_bound<'py>( ty: &Bound<'py, PyType>, obj: &Bound<'py, PyAny>, ) -> PyResult> { diff --git a/tests/test_super.rs b/tests/test_super.rs index dca12457011..b71eae55376 100644 --- a/tests/test_super.rs +++ b/tests/test_super.rs @@ -35,6 +35,7 @@ impl SubClass { } fn method_super_new(self_: &PyCell) -> PyResult<&PyAny> { + #[allow(deprecated)] let super_ = PySuper::new(self_.get_type(), self_)?; super_.call_method("method", (), None) }