Skip to content

Commit

Permalink
Merge pull request #3676 from davidhewitt/any-iter
Browse files Browse the repository at this point in the history
tidy up some Py2 <-> gil-ref conversions
  • Loading branch information
adamreichold committed Dec 20, 2023
2 parents 1b3dc6d + 5181e35 commit fd2fc98
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/instance.rs
Expand Up @@ -1325,7 +1325,7 @@ where
{
/// Extracts `Self` from the source `PyObject`.
fn extract(ob: &'a PyAny) -> PyResult<Self> {
Py2::<PyAny>::borrowed_from_gil_ref(&ob)
Py2::borrowed_from_gil_ref(&ob)
.downcast()
.map(Clone::clone)
.map_err(Into::into)
Expand Down
8 changes: 3 additions & 5 deletions src/types/any.rs
Expand Up @@ -713,11 +713,9 @@ impl PyAny {
/// This is typically a new iterator but if the argument is an iterator,
/// this returns itself.
pub fn iter(&self) -> PyResult<&PyIterator> {
Py2::borrowed_from_gil_ref(&self).iter().map(|py2| {
// Can't use into_gil_ref here because T: PyTypeInfo bound is not satisfied
// Safety: into_ptr produces a valid pointer to PyIterator object
unsafe { self.py().from_owned_ptr(py2.into_ptr()) }
})
Py2::borrowed_from_gil_ref(&self)
.iter()
.map(Py2::into_gil_ref)
}

/// Returns the Python type object for this object's type.
Expand Down

0 comments on commit fd2fc98

Please sign in to comment.