Skip to content

Commit

Permalink
Replace as_ref(py) with Bound APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyFoote committed Feb 18, 2024
1 parent f04ad56 commit 6126024
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ pub trait IntoPy<T>: Sized {
///
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let obj: Py<PyString> = PyString::new_bound(py, "blah").into();
/// let obj = PyString::new_bound(py, "blah");
///
/// // Straight from an owned reference
/// let s: &str = obj.extract(py)?;
/// // From a borrowed reference
/// let s: &str = obj.extract()?;
/// # assert_eq!(s, "blah");
///
/// // Or from a borrowed reference
/// let obj: &PyString = obj.as_ref(py);
/// let s: &str = obj.extract()?;
/// // Or from an owned reference
/// let obj: Py<PyString> = obj.into();
/// let s: &str = obj.extract(py)?;
/// # assert_eq!(s, "blah");
/// # Ok(())
/// })
Expand Down
2 changes: 1 addition & 1 deletion src/err/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ impl PyErrArguments for PyDowncastErrorArguments {
format!(
"'{}' object cannot be converted to '{}'",
self.from
.as_ref(py)
.bind(py)
.qualname()
.as_deref()
.unwrap_or("<failed to extract type name>"),
Expand Down
3 changes: 2 additions & 1 deletion src/pyclass/create_type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
pymethods::{get_doc, get_name, Getter, Setter},
trampoline::trampoline,
},
types::typeobject::PyTypeMethods,
types::PyType,
Py, PyCell, PyClass, PyGetterDef, PyMethodDefType, PyResult, PySetterDef, PyTypeInfo, Python,
};
Expand Down Expand Up @@ -435,7 +436,7 @@ impl PyTypeBuilder {
bpo_45315_workaround(py, class_name);

for cleanup in std::mem::take(&mut self.cleanup) {
cleanup(&self, type_object.as_ref(py).as_type_ptr());
cleanup(&self, type_object.bind(py).as_type_ptr());
}

Ok(PyClassTypeObject {
Expand Down
8 changes: 3 additions & 5 deletions tests/test_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ClassMethod {
#[classmethod]
/// Test class method.
fn method(cls: &Bound<'_, PyType>) -> PyResult<String> {
Ok(format!("{}.method()!", cls.as_gil_ref().qualname()?))
Ok(format!("{}.method()!", cls.qualname()?))
}

#[classmethod]
Expand All @@ -85,10 +85,8 @@ impl ClassMethod {

#[classmethod]
fn method_owned(cls: Py<PyType>) -> PyResult<String> {
Ok(format!(
"{}.method_owned()!",
Python::with_gil(|gil| cls.as_ref(gil).qualname())?
))
let qualname = Python::with_gil(|gil| cls.bind(gil).qualname())?;
Ok(format!("{}.method_owned()!", qualname))
}
}

Expand Down

0 comments on commit 6126024

Please sign in to comment.