Skip to content
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

Add new rule for next(iter(<comprehension>)) and next(iter(<generator>)) #58

Open
ngnpope opened this issue May 5, 2017 · 1 comment

Comments

@ngnpope
Copy link
Contributor

ngnpope commented May 5, 2017

Suggest change from next(iter(<comprehension>)) and next(iter(<generator>)) to next(<generator>) as next() will happily consume a generator. Need to be aware of the default argument to next() in which case the generator will need still to be wrapped in parentheses and the sentinel argument to iter() in which case this change cannot be recommended.

Also note that we cannot have a more generic rule for iter(<comprehension>) to <comprehension> as the type of the former is an iterator and the latter is an iterable (or collection/sequence), e.g. list vs listiterator.

This will work for list, set and tuple comprehensions as they implicitly create iterators, but not for dict.

This change could also apply in other contexts where the return of iter() is not assigned to a variable and will never be reused, e.g. sorted(iter(...)).

@AbdealiLoKo
Copy link

+1 on this
I came across numerous instances of this in projects I was looking at

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

No branches or pull requests

2 participants