10000 Add __length_hint__ support for iterators by coolreader18 · Pull Request #1666 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Add __length_hint__ support for iterators #1666

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 5 commits into from
Jan 10, 2020

Conversation

coolreader18
Copy link
Member

No description provided.

Copy link
Contributor
@palaviv palaviv left a comment

Choose a reason for hiding this comment

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

Looks great. Nice work

@@ -418,3 +418,33 @@ pub fn is_valid_slice_arg(
Ok(None)
}
}

pub fn opt_len(obj: &PyObjectRef, vm: &VirtualMachine) -> Option<PyResult<usize>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should be in VirutalMachine?

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally had it there, but I called it get_len which seemed like a weird name (does it get the length of the VirtualMachine itself?), and it seemed slightly niche to be on VirtualMachine. Idk, it relates to the sequence protocol, so I figured it would best fit in objsequence.

@@ -296,16 +293,11 @@ impl PyItertoolsRepeat {

#[pymethod(name = "__next__")]
fn next(&self, vm: &VirtualMachine) -> PyResult {
if self.times.is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice :)

@coolreader18 coolreader18 force-pushed the coolreader18/length_hint branch from 3d4597d to ae4dc3a Compare January 10, 2020 18:23
@coolreader18 coolreader18 force-pushed the coolreader18/length_hint branch from ae4dc3a to a26e5f2 Compare January 10, 2020 18:24
@coolreader18
Copy link
Member Author

I messed up, pushed the testing commit to master instead of this branch 😩. I'll merge this now.

@coolreader18 coolreader18 merged commit 896f3c4 into master Jan 10, 2020
@coolreader18 coolreader18 deleted the coolreader18/length_hint branch January 14, 2020 17:04
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.

2 participants
0