Skip to content

Commit f37c682

Browse files
authored
Merge pull request #3700 from davidhewitt/super-bound
introduce `PySuper::new_bound`
2 parents ff373eb + d9cc0c0 commit f37c682

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/types/any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
21932193

21942194
#[cfg(not(PyPy))]
21952195
fn py_super(&self) -> PyResult<Bound<'py, PySuper>> {
2196-
PySuper::new2(Bound::borrowed_from_gil_ref(&self.get_type()), self)
2196+
PySuper::new_bound(Bound::borrowed_from_gil_ref(&self.get_type()), self)
21972197
}
21982198
}
21992199

src/types/pysuper.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ pyobject_native_type_core!(
1616
);
1717

1818
impl PySuper {
19+
/// Deprecated form of `PySuper::new_bound`.
20+
#[deprecated(
21+
since = "0.21.0",
22+
note = "`PySuper::new` will be replaced by `PySuper::new_bound` in a future PyO3 version"
23+
)]
24+
pub fn new<'py>(ty: &'py PyType, obj: &'py PyAny) -> PyResult<&'py PySuper> {
25+
Self::new_bound(
26+
Bound::borrowed_from_gil_ref(&ty),
27+
Bound::borrowed_from_gil_ref(&obj),
28+
)
29+
.map(Bound::into_gil_ref)
30+
}
31+
1932
/// Constructs a new super object. More read about super object: [docs](https://docs.python.org/3/library/functions.html#super)
2033
///
2134
/// # Examples
@@ -56,15 +69,7 @@ impl PySuper {
5669
/// }
5770
/// }
5871
/// ```
59-
pub fn new<'py>(ty: &'py PyType, obj: &'py PyAny) -> PyResult<&'py PySuper> {
60-
Self::new2(
61-
Bound::borrowed_from_gil_ref(&ty),
62-
Bound::borrowed_from_gil_ref(&obj),
63-
)
64-
.map(Bound::into_gil_ref)
65-
}
66-
67-
pub(crate) fn new2<'py>(
72+
pub fn new_bound<'py>(
6873
ty: &Bound<'py, PyType>,
6974
obj: &Bound<'py, PyAny>,
7075
) -> PyResult<Bound<'py, PySuper>> {

tests/test_super.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl SubClass {
3535
}
3636

3737
fn method_super_new(self_: &PyCell<Self>) -> PyResult<&PyAny> {
38+
#[allow(deprecated)]
3839
let super_ = PySuper::new(self_.get_type(), self_)?;
3940
super_.call_method("method", (), None)
4041
}

0 commit comments

Comments
 (0)