Skip to content

Add raise_if_stop! macro for protocol/iter.rs #5885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 2, 2025
Merged
17 changes: 17 additions & 0 deletions vm/src/protocol/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,20 @@ where
(self.length_hint.unwrap_or(0), self.length_hint)
}
}

/// Macro to handle `PyIterReturn` values in iterator implementations.
///
/// Extracts the object from `PyIterReturn::Return(obj)` or performs early return
/// for `PyIterReturn::StopIteration(v)`. This macro should only be used within
/// functions that return `PyResult<PyIterReturn>`.
#[macro_export]
macro_rules! raise_if_stop {
($input:expr) => {
match $input {
$crate::protocol::PyIterReturn::Return(obj) => obj,
$crate::protocol::PyIterReturn::StopIteration(v) => {
return Ok($crate::protocol::PyIterReturn::StopIteration(v))
}
}
};
}
Loading
Loading