Skip to content

itertools.compress #1400

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

Merged
merged 1 commit into from
Sep 25, 2019
Merged

itertools.compress #1400

merged 1 commit into from
Sep 25, 2019

Conversation

pitachips
Copy link

implement itertools.compress

@windelbouwman
Copy link
Contributor

Hi @pitachips , thanks for this nice addition! Please check the clippy build on travis. This build should be fixed. The azure build is broken on master, so that probably has a cause unrelated to your change.

Err(e) => return Err(e),
}
} else {
self.next(vm)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that instead of recursion, you may want to prefer a loop here, to prevent hitting recursion limits.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea. I will change it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@windelbouwman I made changes as suggested. Please have a look.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good to me! I had one last comment, then I will merge this work.

let data_obj = call_next(vm, &data_iter);

if verdict {
match data_obj {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This match could be change into a return data_obj statement, since both arms return from the function.

let verdict = objbool::boolval(vm, sel_obj.clone())?;

let data_iter = get_iter(vm, &self.data)?;
let data_obj = call_next(vm, &data_iter);
Copy link
Contributor

@windelbouwman windelbouwman Sep 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to add the question-mark operator to the end of this line, like this:

let data_obj = call_next(vm, &data_iter)?;

What happens, is that in case of Err we return from the function, in case of Ok, we get the value into data_obj.


# itertools.compress
assert list(itertools.compress("ABCDEF", [1,0,1,0,1,1])) == list("ACEF")
assert list(itertools.compress("ABCDEF", [1,0,1,0,1,1])) == list("ACEF")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks the same as the line above it?

#[pymethod(name = "__next__")]
fn next(&self, vm: &VirtualMachine) -> PyResult {
loop {
let selector_iter = get_iter(vm, &self.selector)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment, this call to get_iter might be redundant. It will get the iterator from an iterator. The iterator was already go at line 100, so I think it is sufficient to call the call_next method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's so true. Got rid of the lines. Thanks!

@dralley
Copy link
Contributor

dralley commented Sep 24, 2019

Might want to rebase to kick the CI pipeline and see if it passes.

@dralley
Copy link
Contributor

dralley commented Sep 24, 2019

Leaving a reference to #1361 so that we can see from that thread when it is merged.

@windelbouwman windelbouwman merged commit 90d20fe into RustPython:master Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants