Skip to content

Commit

Permalink
fix proto method extract failure for option
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Mar 20, 2024
1 parent 094787e commit 81b71f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/impl_/extract_argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,27 @@ impl<'a, 'py, T: 'py> PyFunctionArgument<'a, 'py> for &'a Bound<'py, T>
where
T: PyTypeCheck,
{
type Holder = Option<&'a Bound<'py, T>>;
type Holder = Option<()>;

#[inline]
fn extract(
obj: &'a Bound<'py, PyAny>,
holder: &'a mut Option<&'a Bound<'py, T>>,
) -> PyResult<Self> {
Ok(holder.insert(obj.downcast()?))
fn extract(obj: &'a Bound<'py, PyAny>, _: &'a mut Option<()>) -> PyResult<Self> {
obj.downcast().map_err(Into::into)
}
}

impl<'a, 'py, T: 'py> PyFunctionArgument<'a, 'py> for Option<&'a Bound<'py, T>>
where
T: PyTypeCheck,
{
type Holder = ();

#[inline]
fn extract(obj: &'a Bound<'py, PyAny>, _: &'a mut ()) -> PyResult<Self> {
if obj.is_none() {
Ok(None)
} else {
Ok(Some(obj.downcast()?))
}
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/ui/invalid_cancel_handle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ error[E0277]: the trait bound `CancelHandle: Clone` is not satisfied
| ^^^^ the trait `Clone` is not implemented for `CancelHandle`
|
= help: the following other types implement trait `PyFunctionArgument<'a, 'py>`:
Option<&'a pyo3::Bound<'py, T>>
&'a pyo3::Bound<'py, T>
&'a pyo3::coroutine::Coroutine
&'a mut pyo3::coroutine::Coroutine
Expand Down

0 comments on commit 81b71f6

Please sign in to comment.