-
Notifications
You must be signed in to change notification settings - Fork 741
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
PyAnyMethods::iter()
is a footgun, should be called try_iter()
#4550
Labels
Comments
itamarst
changed the title
PyAny::iter() is a footgun, should be called
Sep 12, 2024
try_iter()
PyAny::iter()
is a footgun, should be called try_iter()
itamarst
changed the title
Sep 12, 2024
PyAny::iter()
is a footgun, should be called try_iter()
PySequence::iter()
is a footgun, should be called try_iter()
itamarst
changed the title
Sep 12, 2024
PySequence::iter()
is a footgun, should be called try_iter()
PyAnyMethods::iter()
is a footgun, should be called try_iter()
I think this is a good idea. Either |
I prefer |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Description
PyAnyMethods::iter()
returns aPyResult<&Bound<PyIterator>>
. AndResult
is an iterator. So it's very easy to accidentally iterate over it directly.Steps to Reproduce
Consider the two seemingly identical functions:
They seem identical, but
iterate2()
will iterate over thePyResult
returned fromPyAnyMethods::iter()
, so it will always have a single item, the original sequence!And yes, I just discovered this the hard way.
Your PyO3 version
0.22
Additional Info
I would suggest:
iter()
.try_iter()
. The new name will suggest that it returns aResult<>
and therefore requires a?
or equivalent handler.The text was updated successfully, but these errors were encountered: