Skip to content
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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bschoenmaeckers
Copy link
Contributor

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
Contributor 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
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