-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn instead of error when removed rules are used in ignore
- Loading branch information
1 parent
1d1a14a
commit 25a2336
Showing
5 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use ruff_diagnostics::Violation; | ||
use ruff_macros::violation; | ||
|
||
/// ## Removed | ||
/// There's no [evidence](https://github.com/astral-sh/ruff/issues/12754) that generators are | ||
/// meaningfully faster than list comprehensions when combined with unpacking. | ||
/// | ||
/// ## What it did | ||
/// Checks for list comprehensions that are immediately unpacked. | ||
/// | ||
/// ## Why is this bad? | ||
/// There is no reason to use a list comprehension if the result is immediately | ||
/// unpacked. Instead, use a generator expression, which avoids allocating | ||
/// an intermediary list. | ||
/// | ||
/// ## Example | ||
/// ```python | ||
/// a, b, c = [foo(x) for x in items] | ||
/// ``` | ||
/// | ||
/// Use instead: | ||
/// ```python | ||
/// a, b, c = (foo(x) for x in items) | ||
/// ``` | ||
/// | ||
/// ## References | ||
/// - [Python documentation: Generator expressions](https://docs.python.org/3/reference/expressions.html#generator-expressions) | ||
/// - [Python documentation: List comprehensions](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) | ||
#[violation] | ||
pub struct UnpackedListComprehension; | ||
|
||
impl Violation for UnpackedListComprehension { | ||
fn message(&self) -> String { | ||
unreachable!("UP027 has been removed") | ||
} | ||
|
||
fn message_formats() -> &'static [&'static str] { | ||
&["Replace unpacked list comprehension with a generator expression"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters