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

Enhancement: Add a [consider-using-generator]-checker in any or all calls #3165

Closed
tweakimp opened this issue Oct 5, 2019 · 3 comments · Fixed by #3309
Closed

Enhancement: Add a [consider-using-generator]-checker in any or all calls #3165

tweakimp opened this issue Oct 5, 2019 · 3 comments · Fixed by #3309
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors
Milestone

Comments

@tweakimp
Copy link

tweakimp commented Oct 5, 2019

Problem:
There are many cases of comprehensions inside of any or all calls that are unnecessary and should be replaced by a generator.

For example:

some_list = list(range(1000))
test_old = any([x % 7 == 0 for x in some_list])

Instead, a generator would be less code, and way faster:

test_new = any(x % 7 == 0 for x in some_list)

Speed comparisons:

64 µs ± 1.67 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) # old
447 ns ± 3.48 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) # new

any and all are functions that profit from that because the loop is breaking and can short cut; the remaining elements are not even looped over if the test returns a True in the any function or a False in the all function.

@PCManticore
Copy link
Contributor

Sounds good.

@PCManticore PCManticore added Good first issue Friendly and approachable by new contributors Enhancement ✨ Improvement to a component labels Oct 9, 2019
@ikraduya
Copy link
Contributor

hello,
I am new to pylint, can I work on this?

@PCManticore
Copy link
Contributor

Hi @ikraduya Feel free to work on it! Feel free to work on any issue that doesn't have an assignee, and even if it does, some issues might not be actively worked on by their assignees, so just ask. :)

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.7.0 milestone Feb 20, 2021
Pierre-Sassoulas added a commit that referenced this issue Feb 20, 2021
See issue #3165 (#3309)
See #3309 (comment)

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Daniel Hahler <github@thequod.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants