-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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.
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>> { |
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.
Maybe this should be in VirutalMachine
?
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 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() { |
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.
Nice :)
3d4597d
to
ae4dc3a
Compare
ae4dc3a
to
a26e5f2
Compare
I messed up, pushed the testing commit to master instead of this branch 😩. I'll merge this now. |
No description provided.