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

Feature request: unnecessary-literal-within-deque-call (C409/C418 but for deque) #13515

Open
Avasam opened this issue Sep 25, 2024 · 3 comments
Labels
rule Implementing or modifying a lint rule

Comments

@Avasam
Copy link
Contributor

Avasam commented Sep 25, 2024

Today I found the following code:
self.frame_buffer = deque([], self.frame_buffer_size)

Which, to my understanding, should be the same as
self.frame_buffer = deque(maxlen=self.frame_buffer_size)
(but w/o an extra empty literal, be it a list, tuple, set, etc)

Same with x = deque([])/x = deque(()) --> x = deque()

There may be more collection types for which this idea applies.

I think this could be enforced by a linting rule.

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Sep 25, 2024
@zanieb
Copy link
Member

zanieb commented Sep 26, 2024

This seems reasonable to me. It'd be nice to have a single rule for it.

@MichaReiser
Copy link
Member

To sum up what I understand. The rule would test for deque calls where the first argument is an empty list or tuple literal because that's redundant

@Avasam
Copy link
Contributor Author

Avasam commented Sep 26, 2024

To sum up what I understand. The rule would test for deque calls where the first argument is an empty list or tuple literal because that's redundant

Exactly. Actually any empty iterable if we really wanna be thorough.
But given there's already rules to cover replacing empty iterable calls by literals: At least any empty literal (deque({}) is probably not common, but imo may as well cover it).

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

4 participants