Skip to content

Add itertools.cycle() and itertools.chain.from_iterable() #1645

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 2 commits into from
Dec 25, 2019

Conversation

dralley
Copy link
Contributor

@dralley dralley commented Dec 25, 2019

No description provided.

#[pymethod(name = "__next__")]
fn next(&self, vm: &VirtualMachine) -> PyResult {
let item = if let Some(item) = get_next_object(vm, &self.iter.borrow())? {
if self.first_pass.get() {
Copy link
Contributor Author

@dralley dralley Dec 25, 2019

Choose a reason for hiding this comment

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

So I copied the CPython implementation verbatim basically, but I'm confused as to why this variable exists.

https://github.com/python/cpython/blob/master/Modules/itertoolsmodule.c#L1015-L1043

If you look at the code, it appears it is read from but never written to, except for __setstate__. It looks like a few years ago it was used in the actual algorithm, but not anymore, after this commit:

python/cpython@ca3788c#diff-2e8fa44b11c7ea371dfc1101d176ec87L953

I'm not sure whether it is left behind intentionally (needed for compatibility purposes or something) or if it was an accident.

Copy link
Member

Choose a reason for hiding this comment

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

That's really weird; I think it's fine for now but it'll definitely be interesting to see what the CPython team thinks.

@dralley dralley changed the title Add itertools.cycle() Add itertools.cycle() and itertools.chain.from_iterable() Dec 25, 2019
@dralley
Copy link
Contributor Author

dralley commented Dec 25, 2019

re: #1361

@coolreader18
Copy link
Member

Nice work!

@coolreader18 coolreader18 merged commit 920ef52 into RustPython:master Dec 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.

2 participants