Merge pull request #3700 from davidhewitt/super-bound

introduce `PySuper::new_bound`
This commit is contained in:
Adam Reichold 2023-12-25 09:48:39 +00:00 committed by GitHub
commit f37c682f8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 10 deletions

View File

@ -2193,7 +2193,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
#[cfg(not(PyPy))]
fn py_super(&self) -> PyResult<Bound<'py, PySuper>> {
PySuper::new2(Bound::borrowed_from_gil_ref(&self.get_type()), self)
PySuper::new_bound(Bound::borrowed_from_gil_ref(&self.get_type()), self)
}
}

View File

@ -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<Bound<'py, PySuper>> {

View File

@ -35,6 +35,7 @@ impl SubClass {
}
fn method_super_new(self_: &PyCell<Self>) -> PyResult<&PyAny> {
#[allow(deprecated)]
let super_ = PySuper::new(self_.get_type(), self_)?;
super_.call_method("method", (), None)
}