mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
[ruff
] Preserve parentheses around deque
in fix for unnecessary-empty-iterable-within-deque-call
(RUF037
) (#18598)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
Closes #18552
This commit is contained in:
parent
79006dfb52
commit
caf885c20a
3 changed files with 28 additions and 2 deletions
|
@ -56,3 +56,6 @@ def f():
|
|||
|
||||
def f():
|
||||
queue = deque() # Ok
|
||||
|
||||
def f():
|
||||
x = 0 or(deque)([])
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use ruff_macros::{ViolationMetadata, derive_message_formats};
|
||||
use ruff_python_ast::parenthesize::parenthesized_range;
|
||||
use ruff_python_ast::{self as ast, Expr};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -107,7 +108,15 @@ fn fix_unnecessary_literal_in_deque(
|
|||
deque: &ast::ExprCall,
|
||||
maxlen: Option<&Expr>,
|
||||
) -> Fix {
|
||||
let deque_name = checker.locator().slice(deque.func.range());
|
||||
let deque_name = checker.locator().slice(
|
||||
parenthesized_range(
|
||||
deque.func.as_ref().into(),
|
||||
deque.into(),
|
||||
checker.comment_ranges(),
|
||||
checker.source(),
|
||||
)
|
||||
.unwrap_or(deque.func.range()),
|
||||
);
|
||||
let deque_str = match maxlen {
|
||||
Some(maxlen) => {
|
||||
let len_str = checker.locator().slice(maxlen);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/ruff/mod.rs
|
||||
snapshot_kind: text
|
||||
---
|
||||
RUF037.py:6:13: RUF037 [*] Unnecessary empty iterable within a deque call
|
||||
|
|
||||
|
@ -127,3 +126,18 @@ RUF037.py:30:13: RUF037 [*] Unnecessary empty iterable within a deque call
|
|||
31 31 |
|
||||
32 32 |
|
||||
33 33 | def f():
|
||||
|
||||
RUF037.py:61:13: RUF037 [*] Unnecessary empty iterable within a deque call
|
||||
|
|
||||
60 | def f():
|
||||
61 | x = 0 or(deque)([])
|
||||
| ^^^^^^^^^^^ RUF037
|
||||
|
|
||||
= help: Replace with `deque()`
|
||||
|
||||
ℹ Safe fix
|
||||
58 58 | queue = deque() # Ok
|
||||
59 59 |
|
||||
60 60 | def f():
|
||||
61 |- x = 0 or(deque)([])
|
||||
61 |+ x = 0 or(deque)()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue