-
Notifications
You must be signed in to change notification settings - Fork 770
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
Add PyAnyMethods.try_iter and deprecate .iter #4553
Conversation
Thanks, sounds like |
I've added an example, but I'm open to a better one. |
I nominate: fn does_it_have_the_answer(obj: &Bound<'_, PyAny>) -> bool {
if obj.extract() == Some(42_u8) {
true
} else if obj.extract() == Some("42") {
true
} else if let Ok(iter) = obj.try_iter() {
for item in iter {
if let Ok(item) = item {
if does_it_have_the_answer(item) {
return true;
}
}
}
}
false
} (maybe add some comments to explain what we're doing) |
For my taste that does have a bit too much complexity that is not really relevant for the fallibility of the iterator. I would prefer something a bit simpler, but I don't have a good suggestion in mind right now... At least I think the |
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 as we're a bit stuck of ideas for the perfect example, let's just proceed to merge. I'd prefer see this get into 0.23 with a slightly subpar example and refine another time. Thanks all!
Fixes #4550.