Skip to content

Commit 76dabd4

Browse files
authored
Replace as_ref(py) with Bound APIs (#3863)
1 parent 9a36b50 commit 76dabd4

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/err/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ impl PyErrArguments for PyDowncastErrorArguments {
957957
format!(
958958
"'{}' object cannot be converted to '{}'",
959959
self.from
960-
.as_ref(py)
960+
.bind(py)
961961
.qualname()
962962
.as_deref()
963963
.unwrap_or("<failed to extract type name>"),

src/pyclass/create_type_object.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
pymethods::{get_doc, get_name, Getter, Setter},
1212
trampoline::trampoline,
1313
},
14+
types::typeobject::PyTypeMethods,
1415
types::PyType,
1516
Py, PyCell, PyClass, PyGetterDef, PyMethodDefType, PyResult, PySetterDef, PyTypeInfo, Python,
1617
};
@@ -434,7 +435,7 @@ impl PyTypeBuilder {
434435
bpo_45315_workaround(py, class_name);
435436

436437
for cleanup in std::mem::take(&mut self.cleanup) {
437-
cleanup(&self, type_object.as_ref(py).as_type_ptr());
438+
cleanup(&self, type_object.bind(py).as_type_ptr());
438439
}
439440

440441
Ok(PyClassTypeObject {

tests/test_methods.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl ClassMethod {
7373
#[classmethod]
7474
/// Test class method.
7575
fn method(cls: &Bound<'_, PyType>) -> PyResult<String> {
76-
Ok(format!("{}.method()!", cls.as_gil_ref().qualname()?))
76+
Ok(format!("{}.method()!", cls.qualname()?))
7777
}
7878

7979
#[classmethod]
@@ -84,10 +84,8 @@ impl ClassMethod {
8484

8585
#[classmethod]
8686
fn method_owned(cls: Py<PyType>) -> PyResult<String> {
87-
Ok(format!(
88-
"{}.method_owned()!",
89-
Python::with_gil(|gil| cls.as_ref(gil).qualname())?
90-
))
87+
let qualname = Python::with_gil(|gil| cls.bind(gil).qualname())?;
88+
Ok(format!("{}.method_owned()!", qualname))
9189
}
9290
}
9391

0 commit comments

Comments
 (0)