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

Removing unnecessary list() for generators #10361

Closed
spaceby opened this issue Mar 12, 2024 · 4 comments
Closed

Removing unnecessary list() for generators #10361

spaceby opened this issue Mar 12, 2024 · 4 comments
Labels
rule Implementing or modifying a lint rule

Comments

@spaceby
Copy link

spaceby commented Mar 12, 2024

Can you add the following rules?

a.extend([i for i in range(10)]) to a.extend(i for i in range(10))
a.extend(list(range(10)) to a.extend(range(10)

' '.join([i for i in range(10)]) to ' '.join(i for i in range(10))
' '.join(list(range(10)) to ' '.join(range(10)

[1, *list(range(10))] to [1, *range(10)]

itertools.starmap(func, zip(range(5), range(5))) to map(func, range(5), range(5))

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Mar 15, 2024
@charliermarsh
Copy link
Member

Seems reasonable although the extend could be wrong if we don't know that a is a list; similarly, changing .join could be wrong if we don't know that the caller is a string. Just caveats.

@MichaReiser
Copy link
Member

This seems similar to https://docs.astral.sh/ruff/rules/unnecessary-comprehension-any-all/ What's unclear to me is if this should be a new rule or if the existing rule should be changed to detect any unnecessary list generators.

@charliermarsh
Copy link
Member

I'd say one rule, for built-in methods that consume generators.

@charliermarsh
Copy link
Member

This can be merged into #3259.

@charliermarsh charliermarsh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants