Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::Violation;
use crate::checkers::ast::Checker;

/// ## What it does
/// Checks for `for` loops that can be replaced by a making a copy of a list.
/// Checks for `for` loops that can be replaced with `list()`.
///
/// ## Why is this bad?
/// When creating a copy of an existing list using a for-loop, prefer
/// `list` or `list.copy` instead. Making a direct copy is more readable and
/// When collecting every item from an iterable into a list using a for-loop,
/// prefer `list()` instead. Creating the list directly is more readable and
/// more performant.
///
/// Using the below as an example, the `list`-based copy is ~2x faster on
/// Using the below as an example, the `list()` call is ~2x faster on
/// Python 3.11.
///
/// Note that, as with all `perflint` rules, this is only intended as a
Expand All @@ -23,15 +23,15 @@ use crate::checkers::ast::Checker;
///
/// ## Example
/// ```python
/// original = list(range(10000))
/// original = range(10000)
/// filtered = []
/// for i in original:
/// filtered.append(i)
/// ```
///
/// Use instead:
/// ```python
/// original = list(range(10000))
/// original = range(10000)
/// filtered = list(original)
/// ```
#[derive(ViolationMetadata)]
Expand All @@ -41,7 +41,7 @@ pub(crate) struct ManualListCopy;
impl Violation for ManualListCopy {
#[derive_message_formats]
fn message(&self) -> String {
"Use `list` or `list.copy` to create a copy of a list".to_string()
"Use `list` to create a list from an iterable".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/perflint/mod.rs
---
PERF402 Use `list` or `list.copy` to create a copy of a list
PERF402 Use `list` to create a list from an iterable
--> PERF402.py:5:9
|
3 | result = []
Expand Down