Merge pull request #3700 from davidhewitt/super-bound
introduce `PySuper::new_bound`
This commit is contained in:
commit
f37c682f8c
|
@ -2193,7 +2193,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
|
||||||
|
|
||||||
#[cfg(not(PyPy))]
|
#[cfg(not(PyPy))]
|
||||||
fn py_super(&self) -> PyResult<Bound<'py, PySuper>> {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,19 @@ pyobject_native_type_core!(
|
||||||
);
|
);
|
||||||
|
|
||||||
impl PySuper {
|
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)
|
/// Constructs a new super object. More read about super object: [docs](https://docs.python.org/3/library/functions.html#super)
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -56,15 +69,7 @@ impl PySuper {
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<'py>(ty: &'py PyType, obj: &'py PyAny) -> PyResult<&'py PySuper> {
|
pub fn new_bound<'py>(
|
||||||
Self::new2(
|
|
||||||
Bound::borrowed_from_gil_ref(&ty),
|
|
||||||
Bound::borrowed_from_gil_ref(&obj),
|
|
||||||
)
|
|
||||||
.map(Bound::into_gil_ref)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn new2<'py>(
|
|
||||||
ty: &Bound<'py, PyType>,
|
ty: &Bound<'py, PyType>,
|
||||||
obj: &Bound<'py, PyAny>,
|
obj: &Bound<'py, PyAny>,
|
||||||
) -> PyResult<Bound<'py, PySuper>> {
|
) -> PyResult<Bound<'py, PySuper>> {
|
||||||
|
|
|
@ -35,6 +35,7 @@ impl SubClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn method_super_new(self_: &PyCell<Self>) -> PyResult<&PyAny> {
|
fn method_super_new(self_: &PyCell<Self>) -> PyResult<&PyAny> {
|
||||||
|
#[allow(deprecated)]
|
||||||
let super_ = PySuper::new(self_.get_type(), self_)?;
|
let super_ = PySuper::new(self_.get_type(), self_)?;
|
||||||
super_.call_method("method", (), None)
|
super_.call_method("method", (), None)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue