-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix itertools.pairwise
#5884
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
Fix itertools.pairwise
#5884
Conversation
WalkthroughThe update refactors the Changes
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yml ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (11)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
@@ -1183,7 +1183,7 @@ def test_pairwise(self): | |||
pairwise(None) # non-iterable argument | |||
|
|||
# TODO: RUSTPYTHON | |||
@unittest.skip("TODO: RUSTPYTHON, hangs") | |||
@unittest.expectedFailure | |||
def test_pairwise_reenter(self): |
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've tried to make this test to pass as well, but for some reason when it's reentering the iter old
gets reset to None, causing the next old
to advance the iter one more time than needed.
So for the first assert:
Expected: ([1], ([1], [3]))
Got: ([1], ([3], [4]))
If someone can guide me where to investigate it would be great:)
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.
when new returned Err, the value of old need to be stored in zelf.old
to prevent not to be lost
vm/src/stdlib/itertools.rs
Outdated
@@ -1959,18 +1959,25 @@ mod decl { | |||
|
|||
impl IterNext for PyItertoolsPairwise { | |||
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> { | |||
let old = match zelf.old.read().clone() { | |||
let old_guard = { |
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.
This is not a clone of old_guard, but clone of old, right?
let old_guard = { | |
let old = { |
or
let old_guard = { | |
let old_cloned = { |
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.
yup, that's a more fitting name
PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)), | ||
}, | ||
Some(obj) => obj, | ||
}; | ||
|
||
let new = match zelf.iterator.next(vm)? { | ||
PyIterReturn::Return(obj) => obj, | ||
PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)), |
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.
old seems like to be stored in this case.
PyIterReturn::Return(obj) => obj, | ||
PyIterReturn::Return(obj) => { | ||
// Needed for when we reenter | ||
*zelf.old.write() = Some(obj.clone()); |
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.
instead of immediately after getting the value
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.
IIRC I tried to do it here first but then the tests failed, will recheck
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.
oh, you are right. I was misunderstanding the spec of pairwise. Thank you!
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 tried to save it in the new
block, then the tests won't pass:/
Summary by CodeRabbit