Skip to content

Commit

Permalink
simplify a few uses of BoundObject (#4706)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt authored Nov 14, 2024
1 parent 147f7ef commit ee229cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,13 @@ impl Coroutine {
}

#[getter]
fn __qualname__(&self, py: Python<'_>) -> PyResult<Py<PyString>> {
fn __qualname__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyString>> {
match (&self.name, &self.qualname_prefix) {
(Some(name), Some(prefix)) => format!("{}.{}", prefix, name.bind(py).to_cow()?)
.as_str()
.into_pyobject(py)
.map(BoundObject::unbind)
.map_err(Into::into),
(Some(name), None) => Ok(name.clone_ref(py)),
(Some(name), Some(prefix)) => Ok(PyString::new(
py,
&format!("{}.{}", prefix, name.bind(py).to_cow()?),
)),
(Some(name), None) => Ok(name.bind(py).clone()),
(None, _) => Err(PyAttributeError::new_err("__qualname__")),
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/test_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl MethSignature {
kwargs.into_pyobject(py)?.into_any().into_bound(),
]
.into_pyobject(py)
.map(BoundObject::unbind)
.map(Bound::unbind)
}

#[pyo3(signature = (a=0, /, **kwargs))]
Expand All @@ -305,7 +305,7 @@ impl MethSignature {
kwargs.into_pyobject(py)?.into_any().into_bound(),
]
.into_pyobject(py)
.map(BoundObject::unbind)
.map(Bound::unbind)
}

#[pyo3(signature = (*, a = 2, b = 3))]
Expand Down Expand Up @@ -333,7 +333,7 @@ impl MethSignature {
(args, a)
.into_pyobject(py)
.map(BoundObject::into_any)
.map(BoundObject::unbind)
.map(Bound::unbind)
}

#[pyo3(signature = (a, b = 2, *, c = 3))]
Expand All @@ -358,7 +358,7 @@ impl MethSignature {
kwargs.into_pyobject(py)?.into_any().into_bound(),
]
.into_pyobject(py)
.map(BoundObject::unbind)
.map(Bound::unbind)
}

// "args" can be anything that can be extracted from PyTuple
Expand Down
2 changes: 1 addition & 1 deletion tests/test_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn ext_vararg_fn(py: Python<'_>, a: i32, args: &Bound<'_, PyTuple>) -> PyResult<
args.as_any().clone(),
]
.into_pyobject(py)
.map(BoundObject::unbind)
.map(Bound::unbind)
}

#[pymodule]
Expand Down

0 comments on commit ee229cf

Please sign in to comment.