-
Notifications
You must be signed in to change notification settings - Fork 854
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
Conversation
9cd432e
to
00708ec
Compare
There was a problem hiding this 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.
src/types/iterator.rs
Outdated
} | ||
|
||
impl<'py> Bound<'py, PyIterator> { | ||
/// Sends a value into the iterator. |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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 theyield
keyword in Python? I wonder, is there a way we can replicate theyield
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.
Also needs both |
a2265a7
to
24e5272
Compare
24e5272
to
efc4dad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
Added the missing return value of
ffi::PyIter_Send
and made a safe wrapper in PyIterator for convenience,closes #4727