Skip to content

improve signature of ffi::PyIter_Send & add PyIterator::send #4746

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 2 commits into from
Mar 7, 2025

Conversation

bschoenmaeckers
Copy link
Member

Added the missing return value of ffi::PyIter_Send and made a safe wrapper in PyIterator for convenience,

closes #4727

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for this! I think this looks good to me, with just a thought on documentation.

}

impl<'py> Bound<'py, PyIterator> {
/// Sends a value into the iterator.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be helpful to link users to more documentation about how this works, and/or write something like "equivalent to self.send(value). Similarly I guess PySendResult, while pretty clear from the names, might be worth having comments like "the generator yielded another value" or "the generator returned".

I say generator above... I guess this function only makes sense for generators? (As far as I know, send is always paired with the yield keyword in Python? I wonder, is there a way we can replicate the yield in Rust?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say generator above... I guess this function only makes sense for generators? (As far as I know, send is always paired with the yield keyword in Python? I wonder, is there a way we can replicate the yield in Rust?)

We cannot distinguish between normal python iterators and generators (because they are the same). A normal iterator just ignores the value being send.

@davidhewitt
Copy link
Member

Also needs both fixed and added newsfragments, please.

@bschoenmaeckers bschoenmaeckers force-pushed the py_iter_send branch 3 times, most recently from a2265a7 to 24e5272 Compare December 9, 2024 20:21
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@davidhewitt davidhewitt added this pull request to the merge queue Feb 28, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 28, 2025
@davidhewitt davidhewitt mentioned this pull request Mar 7, 2025
@davidhewitt davidhewitt added this pull request to the merge queue Mar 7, 2025
Merged via the queue into PyO3:main with commit 295e67a Mar 7, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing PySendResult return type for pyo3::ffi::PyIter_Send
2 participants