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

[RUF] Add rule to detect empty literal in deque call (RUF025) #15104

Merged
merged 8 commits into from
Jan 3, 2025

Conversation

w0nder1ng
Copy link
Contributor

Summary

The idea comes from #13515. When you create a collections.deque, it will be empty by default. You can pass an iterable as the first argument, but if the iterable is empty, then it is unnecessary.

from collections import deque

queue = deque([], 5)

Becomes:

from collections import deque

queue = deque(maxlen=5)

Test plan

I added test cases for most of the obvious ways this should apply.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Nice thanks

I think we have to rename the rule to avoid naming collisions with flake8-comprehensions in the future

@dhruvmanila dhruvmanila added rule Implementing or modifying a lint rule preview Related to preview mode features labels Dec 24, 2024
Copy link
Contributor

github-actions bot commented Jan 3, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+3 -0 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)

RasaHQ/rasa (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ tests/core/training/test_interactive.py:663:58: RUF025 [*] Unnecessary empty iterable within a deque call

apache/airflow (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ tests/jobs/test_scheduler_job.py:5887:38: RUF025 [*] Unnecessary empty iterable within a deque call
+ tests/jobs/test_scheduler_job.py:5888:43: RUF025 [*] Unnecessary empty iterable within a deque call

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF025 3 3 0 0 0

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser changed the title [flake8_comprehensions] Add rule to detect empty literal in deque call [RUF] Add rule to detect empty literal in deque call (RUF025) Jan 3, 2025
@MichaReiser MichaReiser merged commit 0837cdd into astral-sh:main Jan 3, 2025
21 checks passed
dcreager added a commit that referenced this pull request Jan 3, 2025
* main:
  [`ruff`] Avoid reporting when `ndigits` is possibly negative (`RUF057`) (#15234)
  Attribute panics to the mdtests that cause them (#15241)
  Show errors for attempted fixes only when passed `--verbose` (#15237)
  [`RUF`] Add rule to detect empty literal in deque call (`RUF025`) (#15104)
  TD003: remove issue code length restriction (#15175)
  Preserve multiline implicit concatenated strings in docstring positions (#15126)
  [`pyflakes`] Ignore errors in `@no_type_check` string annotations (`F722`, `F821`) (#15215)
  style(AIR302): rename removed_airflow_plugin_extension as check_airflow_plugin_extension (#15233)
  [`pylint`] Re-implement `unreachable` (`PLW0101`) (#10891)
  refactor(AIR303): move duplicate qualified_name.to_string() to Diagnostic argument (#15220)
  Misc. clean up to rounding rules (#15231)
  Avoid syntax error when removing int over multiple lines (#15230)
  Migrate renovate config (#15228)
  Remove `Type::tuple` in favor of `TupleType::from_elements` (#15218)
@oprypin
Copy link

oprypin commented Jan 4, 2025

I opened an issue with this PR:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants