-
Notifications
You must be signed in to change notification settings - Fork 802
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
try_iter()
PyAny::iter()
is a footgun, should be called try_iter()
PyAny::iter()
is a footgun, should be called try_iter()
PySequence::iter()
is a footgun, should be called try_iter()
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 |
LilyFoote
added a commit
to LilyFoote/pyo3
that referenced
this issue
Sep 13, 2024
LilyFoote
added a commit
to LilyFoote/pyo3
that referenced
this issue
Sep 13, 2024
|
github-merge-queue bot
pushed a commit
that referenced
this issue
Oct 5, 2024
* Add PyAnyMethods.try_iter and deprecate .iter Fixes #4550. * Rename newsfragment to use PR number * Add example to try_iter docs
masklinn
added a commit
to masklinn/uap-rust
that referenced
this issue
Dec 7, 2024
- bunch of minor bumps (regex, serde, a few direct and indirect dev dependencies) - pyo3 bumped to 0.23 which deprecates the `*_bound` APIs, impact that, also PyO3/pyo3#4550
masklinn
added a commit
to ua-parser/uap-rust
that referenced
this issue
Dec 7, 2024
- bunch of minor bumps (regex, serde, a few direct and indirect dev dependencies) - pyo3 bumped to 0.23 which deprecates the `*_bound` APIs, impact that, also PyO3/pyo3#4550
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: