diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs index d09c738f16eea..4761c80b88fa1 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs @@ -295,7 +295,7 @@ pub(crate) fn fix_unnecessary_collection_call( /// Re-formats the given expression for use within a formatted string. /// -/// For example, when converting a `dict` call to a dictionary literal within +/// For example, when converting a `dict()` call to a dictionary literal within /// a formatted string, we might naively generate the following code: /// /// ```python diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs index d713b2bb366c5..6262b932b11a0 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs @@ -8,18 +8,18 @@ use crate::checkers::ast::Checker; use crate::rules::flake8_comprehensions::fixes; /// ## What it does -/// Checks for unnecessary `list` or `reversed` calls around `sorted` +/// Checks for unnecessary `list()` or `reversed()` calls around `sorted()` /// calls. /// /// ## Why is this bad? -/// It is unnecessary to use `list` around `sorted`, as the latter already +/// It is unnecessary to use `list()` around `sorted()`, as the latter already /// returns a list. /// -/// It is also unnecessary to use `reversed` around `sorted`, as the latter +/// It is also unnecessary to use `reversed()` around `sorted()`, as the latter /// has a `reverse` argument that can be used in lieu of an additional -/// `reversed` call. +/// `reversed()` call. /// -/// In both cases, it's clearer to avoid the redundant call. +/// In both cases, it's clearer and more efficient to avoid the redundant call. /// /// ## Examples /// ```python @@ -32,27 +32,27 @@ use crate::rules::flake8_comprehensions::fixes; /// ``` /// /// ## Fix safety -/// This rule's fix is marked as unsafe, as `reversed` and `reverse=True` will +/// This rule's fix is marked as unsafe, as `reversed()` and `reverse=True` will /// yield different results in the event of custom sort keys or equality -/// functions. Specifically, `reversed` will reverse the order of the -/// collection, while `sorted` with `reverse=True` will perform a stable +/// functions. Specifically, `reversed()` will reverse the order of the +/// collection, while `sorted()` with `reverse=True` will perform a stable /// reverse sort, which will preserve the order of elements that compare as /// equal. #[derive(ViolationMetadata)] pub(crate) struct UnnecessaryCallAroundSorted { - func: String, + func: UnnecessaryFunction, } impl AlwaysFixableViolation for UnnecessaryCallAroundSorted { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryCallAroundSorted { func } = self; - format!("Unnecessary `{func}` call around `sorted()`") + format!("Unnecessary `{func}()` call around `sorted()`") } fn fix_title(&self) -> String { let UnnecessaryCallAroundSorted { func } = self; - format!("Remove unnecessary `{func}` call") + format!("Remove unnecessary `{func}()` call") } } @@ -73,27 +73,55 @@ pub(crate) fn unnecessary_call_around_sorted( let Some(outer_func_name) = semantic.resolve_builtin_symbol(outer_func) else { return; }; - if !matches!(outer_func_name, "list" | "reversed") { + let Some(unnecessary_function) = UnnecessaryFunction::try_from_str(outer_func_name) else { return; - } + }; if !semantic.match_builtin_expr(inner_func, "sorted") { return; } let mut diagnostic = Diagnostic::new( UnnecessaryCallAroundSorted { - func: outer_func_name.to_string(), + func: unnecessary_function, }, expr.range(), ); diagnostic.try_set_fix(|| { - Ok(Fix::applicable_edit( - fixes::fix_unnecessary_call_around_sorted(expr, checker.locator(), checker.stylist())?, - if outer_func_name == "reversed" { - Applicability::Unsafe - } else { - Applicability::Safe - }, - )) + let edit = + fixes::fix_unnecessary_call_around_sorted(expr, checker.locator(), checker.stylist())?; + let applicability = match unnecessary_function { + UnnecessaryFunction::List => Applicability::Safe, + UnnecessaryFunction::Reversed => Applicability::Unsafe, + }; + Ok(Fix::applicable_edit(edit, applicability)) }); checker.diagnostics.push(diagnostic); } + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +enum UnnecessaryFunction { + List, + Reversed, +} + +impl UnnecessaryFunction { + fn try_from_str(name: &str) -> Option { + match name { + "list" => Some(Self::List), + "reversed" => Some(Self::Reversed), + _ => None, + } + } + + const fn as_str(self) -> &'static str { + match self { + Self::List => "list", + Self::Reversed => "reversed", + } + } +} + +impl std::fmt::Display for UnnecessaryFunction { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.as_str()) + } +} diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs index ef0da178c4b17..c5b43ff389951 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs @@ -9,7 +9,7 @@ use crate::rules::flake8_comprehensions::fixes::{pad_end, pad_start}; use crate::rules::flake8_comprehensions::settings::Settings; /// ## What it does -/// Checks for unnecessary `dict`, `list` or `tuple` calls that can be +/// Checks for unnecessary `dict()`, `list()` or `tuple()` calls that can be /// rewritten as empty literals. /// /// ## Why is this bad? @@ -41,14 +41,14 @@ use crate::rules::flake8_comprehensions::settings::Settings; /// - `lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments` #[derive(ViolationMetadata)] pub(crate) struct UnnecessaryCollectionCall { - obj_type: String, + kind: Collection, } impl AlwaysFixableViolation for UnnecessaryCollectionCall { #[derive_message_formats] fn message(&self) -> String { - let UnnecessaryCollectionCall { obj_type } = self; - format!("Unnecessary `{obj_type}` call (rewrite as a literal)") + let UnnecessaryCollectionCall { kind } = self; + format!("Unnecessary `{kind}()` call (rewrite as a literal)") } fn fix_title(&self) -> String { @@ -88,12 +88,8 @@ pub(crate) fn unnecessary_collection_call( _ => return, }; - let mut diagnostic = Diagnostic::new( - UnnecessaryCollectionCall { - obj_type: builtin.to_string(), - }, - call.range(), - ); + let mut diagnostic = + Diagnostic::new(UnnecessaryCollectionCall { kind: collection }, call.range()); // Convert `dict()` to `{}`. if call.arguments.keywords.is_empty() { @@ -136,8 +132,25 @@ pub(crate) fn unnecessary_collection_call( checker.diagnostics.push(diagnostic); } +#[derive(Debug, Copy, Clone, PartialEq, Eq)] enum Collection { Tuple, List, Dict, } + +impl Collection { + const fn as_str(self) -> &'static str { + match self { + Self::Dict => "dict", + Self::List => "list", + Self::Tuple => "tuple", + } + } +} + +impl std::fmt::Display for Collection { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.as_str()) + } +} diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs index 13fdc25d5c871..13e32d5ef94a1 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs @@ -9,10 +9,10 @@ use crate::checkers::ast::Checker; use crate::rules::flake8_comprehensions::fixes; /// ## What it does -/// Checks for unnecessary `dict`, `list`, and `set` comprehension. +/// Checks for unnecessary dict, list, and set comprehension. /// /// ## Why is this bad? -/// It's unnecessary to use a `dict`/`list`/`set` comprehension to build a data structure if the +/// It's unnecessary to use a dict/list/set comprehension to build a data structure if the /// elements are unchanged. Wrap the iterable with `dict()`, `list()`, or `set()` instead. /// /// ## Examples @@ -32,9 +32,9 @@ use crate::rules::flake8_comprehensions::fixes; /// ## Known problems /// /// This rule may produce false positives for dictionary comprehensions that iterate over a mapping. -/// The `dict` constructor behaves differently depending on if it receives a sequence (e.g., a -/// `list`) or a mapping (e.g., a `dict`). When a comprehension iterates over the keys of a mapping, -/// replacing it with a `dict` constructor call will give a different result. +/// The dict constructor behaves differently depending on if it receives a sequence (e.g., a +/// list) or a mapping (e.g., a dict). When a comprehension iterates over the keys of a mapping, +/// replacing it with a `dict()` constructor call will give a different result. /// /// For example: /// @@ -58,36 +58,36 @@ use crate::rules::flake8_comprehensions::fixes; /// Additionally, this fix may drop comments when rewriting the comprehension. #[derive(ViolationMetadata)] pub(crate) struct UnnecessaryComprehension { - obj_type: String, + kind: ComprehensionKind, } impl AlwaysFixableViolation for UnnecessaryComprehension { #[derive_message_formats] fn message(&self) -> String { - let UnnecessaryComprehension { obj_type } = self; - format!("Unnecessary `{obj_type}` comprehension (rewrite using `{obj_type}()`)") + let UnnecessaryComprehension { kind } = self; + format!("Unnecessary {kind} comprehension (rewrite using `{kind}()`)") } fn fix_title(&self) -> String { - let UnnecessaryComprehension { obj_type } = self; - format!("Rewrite using `{obj_type}()`") + let UnnecessaryComprehension { kind } = self; + format!("Rewrite using `{kind}()`") } } /// Add diagnostic for C416 based on the expression node id. fn add_diagnostic(checker: &mut Checker, expr: &Expr) { - let id = match expr { - Expr::ListComp(_) => "list", - Expr::SetComp(_) => "set", - Expr::DictComp(_) => "dict", - _ => return, + let Some(comprehension_kind) = ComprehensionKind::try_from_expr(expr) else { + return; }; - if !checker.semantic().has_builtin_binding(id) { + if !checker + .semantic() + .has_builtin_binding(comprehension_kind.as_str()) + { return; } let mut diagnostic = Diagnostic::new( UnnecessaryComprehension { - obj_type: id.to_string(), + kind: comprehension_kind, }, expr.range(), ); @@ -145,3 +145,35 @@ pub(crate) fn unnecessary_list_set_comprehension( } add_diagnostic(checker, expr); } + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +enum ComprehensionKind { + List, + Set, + Dict, +} + +impl ComprehensionKind { + const fn as_str(self) -> &'static str { + match self { + Self::List => "list", + Self::Dict => "dict", + Self::Set => "set", + } + } + + const fn try_from_expr(expr: &Expr) -> Option { + match expr { + Expr::ListComp(_) => Some(Self::List), + Expr::DictComp(_) => Some(Self::Dict), + Expr::SetComp(_) => Some(Self::Set), + _ => None, + } + } +} + +impl std::fmt::Display for ComprehensionKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.as_str()) + } +} diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs index a723ba4e59351..3d2efb2f79ca7 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs @@ -9,11 +9,11 @@ use ruff_text_size::{Ranged, TextRange}; use crate::checkers::ast::Checker; /// ## What it does -/// Checks for unnecessary `dict` comprehension when creating a dictionary from +/// Checks for unnecessary dict comprehension when creating a dictionary from /// an iterable. /// /// ## Why is this bad? -/// It's unnecessary to use a `dict` comprehension to build a dictionary from +/// It's unnecessary to use a dict comprehension to build a dictionary from /// an iterable when the value is static. /// /// Prefer `dict.fromkeys(iterable)` over `{value: None for value in iterable}`, @@ -155,7 +155,7 @@ fn is_constant_like(expr: &Expr) -> bool { }) } -/// Generate a [`Fix`] to replace `dict` comprehension with `dict.fromkeys`. +/// Generate a [`Fix`] to replace a dict comprehension with `dict.fromkeys`. /// /// For example: /// - Given `{n: None for n in [1,2,3]}`, generate `dict.fromkeys([1,2,3])`. diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs index b9f836ce5a0b1..73bad332fc953 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs @@ -9,13 +9,13 @@ use crate::checkers::ast::Checker; use crate::rules::flake8_comprehensions::fixes; /// ## What it does -/// Checks for unnecessary `list`, `reversed`, `set`, `sorted`, and `tuple` -/// call within `list`, `set`, `sorted`, and `tuple` calls. +/// Checks for unnecessary `list()`, `reversed()`, `set()`, `sorted()`, and +/// `tuple()` call within `list()`, `set()`, `sorted()`, and `tuple()` calls. /// /// ## Why is this bad? /// It's unnecessary to double-cast or double-process iterables by wrapping -/// the listed functions within an additional `list`, `set`, `sorted`, or -/// `tuple` call. Doing so is redundant and can be confusing for readers. +/// the listed functions within an additional `list()`, `set()`, `sorted()`, or +/// `tuple()` call. Doing so is redundant and can be confusing for readers. /// /// ## Examples /// ```python @@ -27,8 +27,8 @@ use crate::rules::flake8_comprehensions::fixes; /// list(iterable) /// ``` /// -/// This rule applies to a variety of functions, including `list`, `reversed`, -/// `set`, `sorted`, and `tuple`. For example: +/// This rule applies to a variety of functions, including `list()`, `reversed()`, +/// `set()`, `sorted()`, and `tuple()`. For example: /// /// - Instead of `list(list(iterable))`, use `list(iterable)`. /// - Instead of `list(tuple(iterable))`, use `list(iterable)`. @@ -57,12 +57,12 @@ impl AlwaysFixableViolation for UnnecessaryDoubleCastOrProcess { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryDoubleCastOrProcess { inner, outer } = self; - format!("Unnecessary `{inner}` call within `{outer}()`") + format!("Unnecessary `{inner}()` call within `{outer}()`") } fn fix_title(&self) -> String { let UnnecessaryDoubleCastOrProcess { inner, .. } = self; - format!("Remove the inner `{inner}` call") + format!("Remove the inner `{inner}()` call") } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs index e4ffc432bc497..cd17c6a796d82 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs @@ -10,11 +10,11 @@ use crate::rules::flake8_comprehensions::fixes; use super::helpers; /// ## What it does -/// Checks for unnecessary generators that can be rewritten as `dict` +/// Checks for unnecessary generators that can be rewritten as dict /// comprehensions. /// /// ## Why is this bad? -/// It is unnecessary to use `dict` around a generator expression, since +/// It is unnecessary to use `dict()` around a generator expression, since /// there are equivalent comprehensions for these types. Using a /// comprehension is clearer and more idiomatic. /// @@ -37,11 +37,11 @@ pub(crate) struct UnnecessaryGeneratorDict; impl AlwaysFixableViolation for UnnecessaryGeneratorDict { #[derive_message_formats] fn message(&self) -> String { - "Unnecessary generator (rewrite as a `dict` comprehension)".to_string() + "Unnecessary generator (rewrite as a dict comprehension)".to_string() } fn fix_title(&self) -> String { - "Rewrite as a `dict` comprehension".to_string() + "Rewrite as a dict comprehension".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs index e83db15f60d59..cf3d0cb2adf65 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs @@ -11,11 +11,11 @@ use crate::checkers::ast::Checker; use super::helpers; /// ## What it does -/// Checks for unnecessary generators that can be rewritten as `list` -/// comprehensions (or with `list` directly). +/// Checks for unnecessary generators that can be rewritten as list +/// comprehensions (or with `list()` directly). /// /// ## Why is this bad? -/// It is unnecessary to use `list` around a generator expression, since +/// It is unnecessary to use `list()` around a generator expression, since /// there are equivalent comprehensions for these types. Using a /// comprehension is clearer and more idiomatic. /// @@ -51,7 +51,7 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorList { if self.short_circuit { "Unnecessary generator (rewrite using `list()`)".to_string() } else { - "Unnecessary generator (rewrite as a `list` comprehension)".to_string() + "Unnecessary generator (rewrite as a list comprehension)".to_string() } } @@ -59,7 +59,7 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorList { if self.short_circuit { "Rewrite using `list()`".to_string() } else { - "Rewrite as a `list` comprehension".to_string() + "Rewrite as a list comprehension".to_string() } } } @@ -74,49 +74,47 @@ pub(crate) fn unnecessary_generator_list(checker: &mut Checker, call: &ast::Expr ) else { return; }; - if !checker.semantic().has_builtin_binding("list") { - return; - } - let Some(ExprGenerator { + let ast::Expr::Generator(ExprGenerator { elt, generators, parenthesized, .. - }) = argument.as_generator_expr() + }) = argument else { return; }; + if !checker.semantic().has_builtin_binding("list") { + return; + } + // Short-circuit: given `list(x for x in y)`, generate `list(y)` (in lieu of `[x for x in y]`). if let [generator] = generators.as_slice() { if generator.ifs.is_empty() && !generator.is_async { if ComparableExpr::from(elt) == ComparableExpr::from(&generator.target) { - let mut diagnostic = Diagnostic::new( + let diagnostic = Diagnostic::new( UnnecessaryGeneratorList { short_circuit: true, }, call.range(), ); let iterator = format!("list({})", checker.locator().slice(generator.iter.range())); - diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( - iterator, - call.range(), - ))); - checker.diagnostics.push(diagnostic); + let fix = Fix::unsafe_edit(Edit::range_replacement(iterator, call.range())); + checker.diagnostics.push(diagnostic.with_fix(fix)); return; } } } // Convert `list(f(x) for x in y)` to `[f(x) for x in y]`. - let mut diagnostic = Diagnostic::new( + let diagnostic = Diagnostic::new( UnnecessaryGeneratorList { short_circuit: false, }, call.range(), ); - diagnostic.set_fix({ + let fix = { // Replace `list(` with `[`. let call_start = Edit::replacement( "[".to_string(), @@ -153,7 +151,6 @@ pub(crate) fn unnecessary_generator_list(checker: &mut Checker, call: &ast::Expr } else { Fix::unsafe_edits(call_start, [call_end]) } - }); - - checker.diagnostics.push(diagnostic); + }; + checker.diagnostics.push(diagnostic.with_fix(fix)); } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs index 9a60ca0072b4b..514eee6198b75 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs @@ -11,8 +11,8 @@ use crate::rules::flake8_comprehensions::fixes::{pad_end, pad_start}; use super::helpers; /// ## What it does -/// Checks for unnecessary generators that can be rewritten as `set` -/// comprehensions (or with `set` directly). +/// Checks for unnecessary generators that can be rewritten as set +/// comprehensions (or with `set()` directly). /// /// ## Why is this bad? /// It is unnecessary to use `set` around a generator expression, since @@ -49,7 +49,7 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorSet { if self.short_circuit { "Unnecessary generator (rewrite using `set()`)".to_string() } else { - "Unnecessary generator (rewrite as a `set` comprehension)".to_string() + "Unnecessary generator (rewrite as a set comprehension)".to_string() } } @@ -57,7 +57,7 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorSet { if self.short_circuit { "Rewrite using `set()`".to_string() } else { - "Rewrite as a `set` comprehension".to_string() + "Rewrite as a set comprehension".to_string() } } } @@ -72,16 +72,16 @@ pub(crate) fn unnecessary_generator_set(checker: &mut Checker, call: &ast::ExprC ) else { return; }; - if !checker.semantic().has_builtin_binding("set") { - return; - } - let Some(ExprGenerator { + let ast::Expr::Generator(ExprGenerator { elt, generators, .. - }) = argument.as_generator_expr() + }) = argument else { return; }; + if !checker.semantic().has_builtin_binding("set") { + return; + } // Short-circuit: given `set(x for x in y)`, generate `set(y)` (in lieu of `{x for x in y}`). if let [generator] = generators.as_slice() { @@ -105,13 +105,13 @@ pub(crate) fn unnecessary_generator_set(checker: &mut Checker, call: &ast::ExprC } // Convert `set(f(x) for x in y)` to `{f(x) for x in y}`. - let mut diagnostic = Diagnostic::new( + let diagnostic = Diagnostic::new( UnnecessaryGeneratorSet { short_circuit: false, }, call.range(), ); - diagnostic.set_fix({ + let fix = { // Replace `set(` with `}`. let call_start = Edit::replacement( pad_start("{", call.range(), checker.locator(), checker.semantic()), @@ -127,7 +127,6 @@ pub(crate) fn unnecessary_generator_set(checker: &mut Checker, call: &ast::ExprC ); Fix::unsafe_edits(call_start, [call_end]) - }); - - checker.diagnostics.push(diagnostic); + }; + checker.diagnostics.push(diagnostic.with_fix(fix)); } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs index 912912d1bdb4e..5696bfee75efb 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs @@ -11,10 +11,10 @@ use crate::rules::flake8_comprehensions::fixes; use super::helpers; /// ## What it does -/// Checks for unnecessary `list` calls around list comprehensions. +/// Checks for unnecessary `list()` calls around list comprehensions. /// /// ## Why is this bad? -/// It is redundant to use a `list` call around a list comprehension. +/// It is redundant to use a `list()` call around a list comprehension. /// /// ## Examples /// ```python @@ -35,11 +35,11 @@ pub(crate) struct UnnecessaryListCall; impl AlwaysFixableViolation for UnnecessaryListCall { #[derive_message_formats] fn message(&self) -> String { - "Unnecessary `list` call (remove the outer call to `list()`)".to_string() + "Unnecessary `list()` call (remove the outer call to `list()`)".to_string() } fn fix_title(&self) -> String { - "Remove outer `list` call".to_string() + "Remove outer `list()` call".to_string() } } @@ -53,10 +53,10 @@ pub(crate) fn unnecessary_list_call( let Some(argument) = helpers::first_argument_with_matching_function("list", func, args) else { return; }; - if !checker.semantic().has_builtin_binding("list") { + if !argument.is_list_comp_expr() { return; } - if !argument.is_list_comp_expr() { + if !checker.semantic().has_builtin_binding("list") { return; } let mut diagnostic = Diagnostic::new(UnnecessaryListCall, expr.range()); diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs index 7aee84e3c5238..eaa7cdf5dbe74 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs @@ -13,7 +13,7 @@ use super::helpers; /// Checks for unnecessary list comprehensions. /// /// ## Why is this bad? -/// It's unnecessary to use a list comprehension inside a call to `dict`, +/// It's unnecessary to use a list comprehension inside a call to `dict()`, /// since there is an equivalent comprehension for this type. /// /// ## Examples @@ -35,11 +35,11 @@ pub(crate) struct UnnecessaryListComprehensionDict; impl AlwaysFixableViolation for UnnecessaryListComprehensionDict { #[derive_message_formats] fn message(&self) -> String { - "Unnecessary `list` comprehension (rewrite as a `dict` comprehension)".to_string() + "Unnecessary list comprehension (rewrite as a dict comprehension)".to_string() } fn fix_title(&self) -> String { - "Rewrite as a `dict` comprehension".to_string() + "Rewrite as a dict comprehension".to_string() } } @@ -56,9 +56,6 @@ pub(crate) fn unnecessary_list_comprehension_dict( else { return; }; - if !checker.semantic().has_builtin_binding("dict") { - return; - } let Expr::ListComp(ast::ExprListComp { elt, .. }) = argument else { return; }; @@ -68,6 +65,9 @@ pub(crate) fn unnecessary_list_comprehension_dict( if tuple.len() != 2 { return; } + if !checker.semantic().has_builtin_binding("dict") { + return; + } let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionDict, expr.range()); diagnostic.try_set_fix(|| { fixes::fix_unnecessary_list_comprehension_dict(expr, checker).map(Fix::unsafe_edit) diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs index 383c90a89605c..6fdee558c78aa 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs @@ -12,7 +12,7 @@ use super::helpers; /// Checks for unnecessary list comprehensions. /// /// ## Why is this bad? -/// It's unnecessary to use a list comprehension inside a call to `set`, +/// It's unnecessary to use a list comprehension inside a call to `set()`, /// since there is an equivalent comprehension for this type. /// /// ## Examples @@ -34,11 +34,11 @@ pub(crate) struct UnnecessaryListComprehensionSet; impl AlwaysFixableViolation for UnnecessaryListComprehensionSet { #[derive_message_formats] fn message(&self) -> String { - "Unnecessary `list` comprehension (rewrite as a `set` comprehension)".to_string() + "Unnecessary list comprehension (rewrite as a set comprehension)".to_string() } fn fix_title(&self) -> String { - "Rewrite as a `set` comprehension".to_string() + "Rewrite as a set comprehension".to_string() } } @@ -56,8 +56,8 @@ pub(crate) fn unnecessary_list_comprehension_set(checker: &mut Checker, call: &a return; } if argument.is_list_comp_expr() { - let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, call.range()); - diagnostic.set_fix({ + let diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, call.range()); + let fix = { // Replace `set(` with `{`. let call_start = Edit::replacement( pad_start("{", call.range(), checker.locator(), checker.semantic()), @@ -80,7 +80,7 @@ pub(crate) fn unnecessary_list_comprehension_set(checker: &mut Checker, call: &a let argument_end = Edit::deletion(argument.end() - TextSize::from(1), argument.end()); Fix::unsafe_edits(call_start, [argument_start, argument_end, call_end]) - }); - checker.diagnostics.push(diagnostic); + }; + checker.diagnostics.push(diagnostic.with_fix(fix)); } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs index 571d915f3f2da..0240e053d6137 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs @@ -10,10 +10,10 @@ use crate::rules::flake8_comprehensions::fixes; use super::helpers; /// ## What it does -/// Checks for unnecessary `list` or `tuple` literals. +/// Checks for unnecessary list or tuple literals. /// /// ## Why is this bad? -/// It's unnecessary to use a list or tuple literal within a call to `dict`. +/// It's unnecessary to use a list or tuple literal within a call to `dict()`. /// It can be rewritten as a dict literal (`{}`). /// /// ## Examples @@ -35,18 +35,18 @@ use super::helpers; /// when rewriting the call. In most cases, though, comments will be preserved. #[derive(ViolationMetadata)] pub(crate) struct UnnecessaryLiteralDict { - obj_type: String, + obj_type: LiteralKind, } impl AlwaysFixableViolation for UnnecessaryLiteralDict { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryLiteralDict { obj_type } = self; - format!("Unnecessary `{obj_type}` literal (rewrite as a `dict` literal)") + format!("Unnecessary {obj_type} literal (rewrite as a dict literal)") } fn fix_title(&self) -> String { - "Rewrite as a `dict` literal".to_string() + "Rewrite as a dict literal".to_string() } } @@ -63,12 +63,9 @@ pub(crate) fn unnecessary_literal_dict( else { return; }; - if !checker.semantic().has_builtin_binding("dict") { - return; - } let (kind, elts) = match argument { - Expr::Tuple(ast::ExprTuple { elts, .. }) => ("tuple", elts), - Expr::List(ast::ExprList { elts, .. }) => ("list", elts), + Expr::Tuple(ast::ExprTuple { elts, .. }) => (LiteralKind::Tuple, elts), + Expr::List(ast::ExprList { elts, .. }) => (LiteralKind::List, elts), _ => return, }; // Accept `dict((1, 2), ...))` `dict([(1, 2), ...])`. @@ -78,13 +75,32 @@ pub(crate) fn unnecessary_literal_dict( { return; } - let mut diagnostic = Diagnostic::new( - UnnecessaryLiteralDict { - obj_type: kind.to_string(), - }, - expr.range(), - ); + if !checker.semantic().has_builtin_binding("dict") { + return; + } + let mut diagnostic = Diagnostic::new(UnnecessaryLiteralDict { obj_type: kind }, expr.range()); diagnostic .try_set_fix(|| fixes::fix_unnecessary_literal_dict(expr, checker).map(Fix::unsafe_edit)); checker.diagnostics.push(diagnostic); } + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +enum LiteralKind { + Tuple, + List, +} + +impl LiteralKind { + const fn as_str(self) -> &'static str { + match self { + Self::Tuple => "tuple", + Self::List => "list", + } + } +} + +impl std::fmt::Display for LiteralKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.as_str()) + } +} diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs index e1de6e7001626..603d00aeae508 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs @@ -9,11 +9,11 @@ use crate::rules::flake8_comprehensions::fixes::{pad_end, pad_start}; use super::helpers; /// ## What it does -/// Checks for `set` calls that take unnecessary `list` or `tuple` literals +/// Checks for `set()` calls that take unnecessary list or tuple literals /// as arguments. /// /// ## Why is this bad? -/// It's unnecessary to use a list or tuple literal within a call to `set`. +/// It's unnecessary to use a list or tuple literal within a call to `set()`. /// Instead, the expression can be rewritten as a set literal. /// /// ## Examples @@ -35,18 +35,18 @@ use super::helpers; /// when rewriting the call. In most cases, though, comments will be preserved. #[derive(ViolationMetadata)] pub(crate) struct UnnecessaryLiteralSet { - obj_type: String, + kind: UnnecessaryLiteral, } impl AlwaysFixableViolation for UnnecessaryLiteralSet { #[derive_message_formats] fn message(&self) -> String { - let UnnecessaryLiteralSet { obj_type } = self; - format!("Unnecessary `{obj_type}` literal (rewrite as a `set` literal)") + let UnnecessaryLiteralSet { kind } = self; + format!("Unnecessary {kind} literal (rewrite as a set literal)") } fn fix_title(&self) -> String { - "Rewrite as a `set` literal".to_string() + "Rewrite as a set literal".to_string() } } @@ -60,21 +60,14 @@ pub(crate) fn unnecessary_literal_set(checker: &mut Checker, call: &ast::ExprCal ) else { return; }; + let Some(kind) = UnnecessaryLiteral::try_from_expr(argument) else { + return; + }; if !checker.semantic().has_builtin_binding("set") { return; } - let kind = match argument { - Expr::List(_) => "list", - Expr::Tuple(_) => "tuple", - _ => return, - }; - let mut diagnostic = Diagnostic::new( - UnnecessaryLiteralSet { - obj_type: kind.to_string(), - }, - call.range(), - ); + let mut diagnostic = Diagnostic::new(UnnecessaryLiteralSet { kind }, call.range()); // Convert `set((1, 2))` to `{1, 2}`. diagnostic.set_fix({ @@ -134,3 +127,32 @@ pub(crate) fn unnecessary_literal_set(checker: &mut Checker, call: &ast::ExprCal checker.diagnostics.push(diagnostic); } + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum UnnecessaryLiteral { + List, + Tuple, +} + +impl UnnecessaryLiteral { + const fn try_from_expr(expr: &Expr) -> Option { + match expr { + Expr::List(_) => Some(Self::List), + Expr::Tuple(_) => Some(Self::Tuple), + _ => None, + } + } + + const fn as_str(self) -> &'static str { + match self { + Self::Tuple => "tuple", + Self::List => "list", + } + } +} + +impl std::fmt::Display for UnnecessaryLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.as_str()) + } +} diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs index 4e4399da91b2b..b3c61b013563a 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs @@ -10,28 +10,14 @@ use crate::checkers::ast::Checker; use super::helpers; -#[derive(Debug, PartialEq, Eq)] -pub(crate) enum DictKind { - Literal, - Comprehension, -} - -impl fmt::Display for DictKind { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - match self { - DictKind::Literal => fmt.write_str("literal"), - DictKind::Comprehension => fmt.write_str("comprehension"), - } - } -} - /// ## What it does -/// Checks for `dict` calls that take unnecessary `dict` literals or `dict` +/// Checks for `dict()` calls that take unnecessary dict literals or dict /// comprehensions as arguments. /// /// ## Why is this bad? -/// It's unnecessary to wrap a `dict` literal or comprehension within a `dict` -/// call, since the literal or comprehension syntax already returns a `dict`. +/// It's unnecessary to wrap a dict literal or comprehension within a `dict()` +/// call, since the literal or comprehension syntax already returns a +/// dictionary. /// /// ## Examples /// ```python @@ -57,11 +43,11 @@ impl AlwaysFixableViolation for UnnecessaryLiteralWithinDictCall { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryLiteralWithinDictCall { kind } = self; - format!("Unnecessary `dict` {kind} passed to `dict()` (remove the outer call to `dict()`)") + format!("Unnecessary dict {kind} passed to `dict()` (remove the outer call to `dict()`)") } fn fix_title(&self) -> String { - "Remove outer `dict` call".to_string() + "Remove outer `dict()` call".to_string() } } @@ -75,14 +61,12 @@ pub(crate) fn unnecessary_literal_within_dict_call(checker: &mut Checker, call: else { return; }; + let Some(argument_kind) = DictKind::try_from_expr(argument) else { + return; + }; if !checker.semantic().has_builtin_binding("dict") { return; } - let argument_kind = match argument { - Expr::DictComp(_) => DictKind::Comprehension, - Expr::Dict(_) => DictKind::Literal, - _ => return, - }; let mut diagnostic = Diagnostic::new( UnnecessaryLiteralWithinDictCall { @@ -104,3 +88,32 @@ pub(crate) fn unnecessary_literal_within_dict_call(checker: &mut Checker, call: checker.diagnostics.push(diagnostic); } + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub(crate) enum DictKind { + Literal, + Comprehension, +} + +impl DictKind { + const fn as_str(self) -> &'static str { + match self { + Self::Literal => "literal", + Self::Comprehension => "comprehension", + } + } + + const fn try_from_expr(expr: &Expr) -> Option { + match expr { + Expr::Dict(_) => Some(Self::Literal), + Expr::DictComp(_) => Some(Self::Comprehension), + _ => None, + } + } +} + +impl fmt::Display for DictKind { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(self.as_str()) + } +} diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs index 317b197ca3850..7dbc47496bb2e 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs @@ -8,7 +8,7 @@ use crate::checkers::ast::Checker; use super::helpers; /// ## What it does -/// Checks for `list` calls that take unnecessary list or tuple literals as +/// Checks for `list()` calls that take unnecessary list or tuple literals as /// arguments. /// /// ## Why is this bad? @@ -17,7 +17,7 @@ use super::helpers; /// /// If a list literal is passed in, then the outer call to `list()` should be /// removed. Otherwise, if a tuple literal is passed in, then it should be -/// rewritten as a `list` literal. +/// rewritten as a list literal. /// /// ## Examples /// ```python @@ -36,33 +36,28 @@ use super::helpers; /// when rewriting the call. In most cases, though, comments will be preserved. #[derive(ViolationMetadata)] pub(crate) struct UnnecessaryLiteralWithinListCall { - literal: String, + kind: LiteralKind, } impl AlwaysFixableViolation for UnnecessaryLiteralWithinListCall { #[derive_message_formats] fn message(&self) -> String { - let UnnecessaryLiteralWithinListCall { literal } = self; - if literal == "list" { - format!( - "Unnecessary `{literal}` literal passed to `list()` (remove the outer call to \ - `list()`)" - ) - } else { - format!( - "Unnecessary `{literal}` literal passed to `list()` (rewrite as a `list` literal)" - ) + match self.kind { + LiteralKind::List => { + "Unnecessary list literal passed to `list()` (remove the outer call to `list()`)" + .to_string() + } + LiteralKind::Tuple => { + "Unnecessary tuple literal passed to `list()` (rewrite as a single list literal)" + .to_string() + } } } fn fix_title(&self) -> String { - let UnnecessaryLiteralWithinListCall { literal } = self; - { - if literal == "list" { - "Remove outer `list` call".to_string() - } else { - "Rewrite as a `list` literal".to_string() - } + match self.kind { + LiteralKind::List => "Remove outer `list()` call".to_string(), + LiteralKind::Tuple => "Rewrite as a single list literal".to_string(), } } } @@ -77,24 +72,22 @@ pub(crate) fn unnecessary_literal_within_list_call(checker: &mut Checker, call: else { return; }; + let Some(argument_kind) = LiteralKind::try_from_expr(argument) else { + return; + }; if !checker.semantic().has_builtin_binding("list") { return; } - let argument_kind = match argument { - Expr::Tuple(_) => "tuple", - Expr::List(_) => "list", - _ => return, - }; - let mut diagnostic = Diagnostic::new( + let diagnostic = Diagnostic::new( UnnecessaryLiteralWithinListCall { - literal: argument_kind.to_string(), + kind: argument_kind, }, call.range(), ); // Convert `list([1, 2])` to `[1, 2]` - diagnostic.set_fix({ + let fix = { // Delete from the start of the call to the start of the argument. let call_start = Edit::deletion(call.start(), argument.start()); @@ -121,7 +114,23 @@ pub(crate) fn unnecessary_literal_within_list_call(checker: &mut Checker, call: } else { Fix::unsafe_edits(call_start, [call_end]) } - }); + }; + + checker.diagnostics.push(diagnostic.with_fix(fix)); +} - checker.diagnostics.push(diagnostic); +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +enum LiteralKind { + Tuple, + List, +} + +impl LiteralKind { + const fn try_from_expr(expr: &Expr) -> Option { + match expr { + Expr::Tuple(_) => Some(Self::Tuple), + Expr::List(_) => Some(Self::List), + _ => None, + } + } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs index d5f5744c68d44..0cec64136ce4c 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs @@ -56,20 +56,23 @@ impl AlwaysFixableViolation for UnnecessaryLiteralWithinTupleCall { fn message(&self) -> String { match self.literal_kind { TupleLiteralKind::List => { - "Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)".to_string() + "Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)" + .to_string() } TupleLiteralKind::Tuple => { - "Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`)".to_string() + "Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`)" + .to_string() } TupleLiteralKind::ListComp => { - "Unnecessary list comprehension passed to `tuple()` (rewrite as a generator)".to_string() + "Unnecessary list comprehension passed to `tuple()` (rewrite as a generator)" + .to_string() } } } fn fix_title(&self) -> String { let title = match self.literal_kind { - TupleLiteralKind::List => "Rewrite as a `tuple` literal", + TupleLiteralKind::List => "Rewrite as a tuple literal", TupleLiteralKind::Tuple => "Remove the outer call to `tuple()`", TupleLiteralKind::ListComp => "Rewrite as a generator", }; @@ -94,15 +97,15 @@ pub(crate) fn unnecessary_literal_within_tuple_call( ) else { return; }; - if !checker.semantic().has_builtin_binding("tuple") { - return; - } let argument_kind = match argument { Expr::Tuple(_) => TupleLiteralKind::Tuple, Expr::List(_) => TupleLiteralKind::List, Expr::ListComp(_) if checker.settings.preview.is_enabled() => TupleLiteralKind::ListComp, _ => return, }; + if !checker.semantic().has_builtin_binding("tuple") { + return; + } let mut diagnostic = Diagnostic::new( UnnecessaryLiteralWithinTupleCall { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs index ce7703b8dfc47..e0811a7e988d5 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs @@ -15,15 +15,15 @@ use crate::rules::flake8_comprehensions::fixes; use super::helpers; /// ## What it does -/// Checks for unnecessary `map` calls with `lambda` functions. +/// Checks for unnecessary `map()` calls with lambda functions. /// /// ## Why is this bad? -/// Using `map(func, iterable)` when `func` is a `lambda` is slower than +/// Using `map(func, iterable)` when `func` is a lambda is slower than /// using a generator expression or a comprehension, as the latter approach /// avoids the function call overhead, in addition to being more readable. /// -/// This rule also applies to `map` calls within `list`, `set`, and `dict` -/// calls. For example: +/// This rule also applies to `map()` calls within `list()`, `set()`, and +/// `dict()` calls. For example: /// /// - Instead of `list(map(lambda num: num * 2, nums))`, use /// `[num * 2 for num in nums]`. @@ -56,12 +56,12 @@ impl Violation for UnnecessaryMap { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryMap { object_type } = self; - format!("Unnecessary `map` usage (rewrite using a {object_type})") + format!("Unnecessary `map()` usage (rewrite using a {object_type})") } fn fix_title(&self) -> Option { let UnnecessaryMap { object_type } = self; - Some(format!("Replace `map` with a {object_type}")) + Some(format!("Replace `map()` with a {object_type}")) } } @@ -237,9 +237,9 @@ impl fmt::Display for ObjectType { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match self { ObjectType::Generator => fmt.write_str("generator expression"), - ObjectType::List => fmt.write_str("`list` comprehension"), - ObjectType::Set => fmt.write_str("`set` comprehension"), - ObjectType::Dict => fmt.write_str("`dict` comprehension"), + ObjectType::List => fmt.write_str("list comprehension"), + ObjectType::Set => fmt.write_str("set comprehension"), + ObjectType::Dict => fmt.write_str("dict comprehension"), } } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C400_C400.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C400_C400.py.snap index 7e946f22f69fb..440342ef81bb1 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C400_C400.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C400_C400.py.snap @@ -1,8 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C400.py:2:13: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) +C400.py:2:13: C400 [*] Unnecessary generator (rewrite as a list comprehension) | 1 | # Cannot combine with C416. Should use list comprehension here. 2 | even_nums = list(2 * x for x in range(3)) @@ -10,7 +9,7 @@ C400.py:2:13: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) 3 | odd_nums = list( 4 | 2 * x + 1 for x in range(3) | - = help: Rewrite as a `list` comprehension + = help: Rewrite as a list comprehension ℹ Unsafe fix 1 1 | # Cannot combine with C416. Should use list comprehension here. @@ -20,7 +19,7 @@ C400.py:2:13: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) 4 4 | 2 * x + 1 for x in range(3) 5 5 | ) -C400.py:3:12: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) +C400.py:3:12: C400 [*] Unnecessary generator (rewrite as a list comprehension) | 1 | # Cannot combine with C416. Should use list comprehension here. 2 | even_nums = list(2 * x for x in range(3)) @@ -30,7 +29,7 @@ C400.py:3:12: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) 5 | | ) | |_^ C400 | - = help: Rewrite as a `list` comprehension + = help: Rewrite as a list comprehension ℹ Unsafe fix 1 1 | # Cannot combine with C416. Should use list comprehension here. @@ -90,7 +89,7 @@ C400.py:10:5: C400 [*] Unnecessary generator (rewrite using `list()`) 14 12 | # Strip parentheses from inner generators. 15 13 | list((2 * x for x in range(3))) -C400.py:15:1: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) +C400.py:15:1: C400 [*] Unnecessary generator (rewrite as a list comprehension) | 14 | # Strip parentheses from inner generators. 15 | list((2 * x for x in range(3))) @@ -98,7 +97,7 @@ C400.py:15:1: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) 16 | list(((2 * x for x in range(3)))) 17 | list((((2 * x for x in range(3))))) | - = help: Rewrite as a `list` comprehension + = help: Rewrite as a list comprehension ℹ Unsafe fix 12 12 | ) @@ -110,7 +109,7 @@ C400.py:15:1: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) 17 17 | list((((2 * x for x in range(3))))) 18 18 | -C400.py:16:1: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) +C400.py:16:1: C400 [*] Unnecessary generator (rewrite as a list comprehension) | 14 | # Strip parentheses from inner generators. 15 | list((2 * x for x in range(3))) @@ -118,7 +117,7 @@ C400.py:16:1: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C400 17 | list((((2 * x for x in range(3))))) | - = help: Rewrite as a `list` comprehension + = help: Rewrite as a list comprehension ℹ Unsafe fix 13 13 | @@ -130,7 +129,7 @@ C400.py:16:1: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) 18 18 | 19 19 | # Not built-in list. -C400.py:17:1: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) +C400.py:17:1: C400 [*] Unnecessary generator (rewrite as a list comprehension) | 15 | list((2 * x for x in range(3))) 16 | list(((2 * x for x in range(3)))) @@ -139,7 +138,7 @@ C400.py:17:1: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) 18 | 19 | # Not built-in list. | - = help: Rewrite as a `list` comprehension + = help: Rewrite as a list comprehension ℹ Unsafe fix 14 14 | # Strip parentheses from inner generators. diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C401_C401.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C401_C401.py.snap index 327946a4cd21a..fab816dd97371 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C401_C401.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C401_C401.py.snap @@ -1,8 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C401.py:2:13: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) +C401.py:2:13: C401 [*] Unnecessary generator (rewrite as a set comprehension) | 1 | # Cannot conbime with C416. Should use set comprehension here. 2 | even_nums = set(2 * x for x in range(3)) @@ -10,7 +9,7 @@ C401.py:2:13: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) 3 | odd_nums = set( 4 | 2 * x + 1 for x in range(3) | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 1 1 | # Cannot conbime with C416. Should use set comprehension here. @@ -20,7 +19,7 @@ C401.py:2:13: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) 4 4 | 2 * x + 1 for x in range(3) 5 5 | ) -C401.py:3:12: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) +C401.py:3:12: C401 [*] Unnecessary generator (rewrite as a set comprehension) | 1 | # Cannot conbime with C416. Should use set comprehension here. 2 | even_nums = set(2 * x for x in range(3)) @@ -31,7 +30,7 @@ C401.py:3:12: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) | |_^ C401 6 | small_nums = f"{set(a if a < 6 else 0 for a in range(3))}" | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 1 1 | # Cannot conbime with C416. Should use set comprehension here. @@ -45,7 +44,7 @@ C401.py:3:12: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) 7 7 | 8 8 | def f(x): -C401.py:6:17: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) +C401.py:6:17: C401 [*] Unnecessary generator (rewrite as a set comprehension) | 4 | 2 * x + 1 for x in range(3) 5 | ) @@ -54,7 +53,7 @@ C401.py:6:17: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) 7 | 8 | def f(x): | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 3 3 | odd_nums = set( @@ -66,7 +65,7 @@ C401.py:6:17: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) 8 8 | def f(x): 9 9 | return x -C401.py:11:16: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) +C401.py:11:16: C401 [*] Unnecessary generator (rewrite as a set comprehension) | 9 | return x 10 | @@ -74,7 +73,7 @@ C401.py:11:16: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) | ^^^^^^^^^^^^^^^^^^^^^^^^ C401 12 | print(f"Hello { set(f(a) for a in 'abc') } World") | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 8 8 | def f(x): @@ -86,13 +85,13 @@ C401.py:11:16: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) 13 13 | 14 14 | -C401.py:12:17: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) +C401.py:12:17: C401 [*] Unnecessary generator (rewrite as a set comprehension) | 11 | print(f"Hello {set(f(a) for a in 'abc')} World") 12 | print(f"Hello { set(f(a) for a in 'abc') } World") | ^^^^^^^^^^^^^^^^^^^^^^^^ C401 | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 9 9 | return x diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C402_C402.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C402_C402.py.snap index 3afb8c581cbbb..58382cb5e424c 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C402_C402.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C402_C402.py.snap @@ -1,15 +1,14 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C402.py:1:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:1:1: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 1 | dict((x, x) for x in range(3)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C402 2 | dict( 3 | (x, x) for x in range(3) | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 1 |-dict((x, x) for x in range(3)) @@ -18,7 +17,7 @@ C402.py:1:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 3 3 | (x, x) for x in range(3) 4 4 | ) -C402.py:2:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:2:1: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 1 | dict((x, x) for x in range(3)) 2 | / dict( @@ -28,7 +27,7 @@ C402.py:2:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 5 | dict(((x, x) for x in range(3)), z=3) 6 | y = f'{dict((x, x) for x in range(3))}' | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 1 1 | dict((x, x) for x in range(3)) @@ -42,7 +41,7 @@ C402.py:2:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 6 6 | y = f'{dict((x, x) for x in range(3))}' 7 7 | print(f'Hello {dict((x, x) for x in range(3))} World') -C402.py:6:8: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:6:8: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 4 | ) 5 | dict(((x, x) for x in range(3)), z=3) @@ -51,7 +50,7 @@ C402.py:6:8: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 7 | print(f'Hello {dict((x, x) for x in range(3))} World') 8 | print(f"Hello {dict((x, x) for x in 'abc')} World") | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 3 3 | (x, x) for x in range(3) @@ -63,7 +62,7 @@ C402.py:6:8: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 8 8 | print(f"Hello {dict((x, x) for x in 'abc')} World") 9 9 | print(f'Hello {dict((x, x) for x in "abc")} World') -C402.py:7:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:7:16: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 5 | dict(((x, x) for x in range(3)), z=3) 6 | y = f'{dict((x, x) for x in range(3))}' @@ -72,7 +71,7 @@ C402.py:7:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 8 | print(f"Hello {dict((x, x) for x in 'abc')} World") 9 | print(f'Hello {dict((x, x) for x in "abc")} World') | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 4 4 | ) @@ -84,7 +83,7 @@ C402.py:7:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 9 9 | print(f'Hello {dict((x, x) for x in "abc")} World') 10 10 | print(f'Hello {dict((x,x) for x in "abc")} World') -C402.py:8:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:8:16: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 6 | y = f'{dict((x, x) for x in range(3))}' 7 | print(f'Hello {dict((x, x) for x in range(3))} World') @@ -93,7 +92,7 @@ C402.py:8:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 9 | print(f'Hello {dict((x, x) for x in "abc")} World') 10 | print(f'Hello {dict((x,x) for x in "abc")} World') | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 5 5 | dict(((x, x) for x in range(3)), z=3) @@ -105,7 +104,7 @@ C402.py:8:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 10 10 | print(f'Hello {dict((x,x) for x in "abc")} World') 11 11 | -C402.py:9:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:9:16: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 7 | print(f'Hello {dict((x, x) for x in range(3))} World') 8 | print(f"Hello {dict((x, x) for x in 'abc')} World") @@ -113,7 +112,7 @@ C402.py:9:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ C402 10 | print(f'Hello {dict((x,x) for x in "abc")} World') | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 6 6 | y = f'{dict((x, x) for x in range(3))}' @@ -125,7 +124,7 @@ C402.py:9:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 11 11 | 12 12 | f'{dict((x, x) for x in range(3)) | dict((x, x) for x in range(3))}' -C402.py:10:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:10:16: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 8 | print(f"Hello {dict((x, x) for x in 'abc')} World") 9 | print(f'Hello {dict((x, x) for x in "abc")} World') @@ -134,7 +133,7 @@ C402.py:10:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension 11 | 12 | f'{dict((x, x) for x in range(3)) | dict((x, x) for x in range(3))}' | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 7 7 | print(f'Hello {dict((x, x) for x in range(3))} World') @@ -146,7 +145,7 @@ C402.py:10:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension 12 12 | f'{dict((x, x) for x in range(3)) | dict((x, x) for x in range(3))}' 13 13 | f'{ dict((x, x) for x in range(3)) | dict((x, x) for x in range(3)) }' -C402.py:12:4: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:12:4: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 10 | print(f'Hello {dict((x,x) for x in "abc")} World') 11 | @@ -154,7 +153,7 @@ C402.py:12:4: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C402 13 | f'{ dict((x, x) for x in range(3)) | dict((x, x) for x in range(3)) }' | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 9 9 | print(f'Hello {dict((x, x) for x in "abc")} World') @@ -166,7 +165,7 @@ C402.py:12:4: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 14 14 | 15 15 | def f(x): -C402.py:12:37: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:12:37: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 10 | print(f'Hello {dict((x,x) for x in "abc")} World') 11 | @@ -174,7 +173,7 @@ C402.py:12:37: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C402 13 | f'{ dict((x, x) for x in range(3)) | dict((x, x) for x in range(3)) }' | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 9 9 | print(f'Hello {dict((x, x) for x in "abc")} World') @@ -186,7 +185,7 @@ C402.py:12:37: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension 14 14 | 15 15 | def f(x): -C402.py:13:5: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:13:5: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 12 | f'{dict((x, x) for x in range(3)) | dict((x, x) for x in range(3))}' 13 | f'{ dict((x, x) for x in range(3)) | dict((x, x) for x in range(3)) }' @@ -194,7 +193,7 @@ C402.py:13:5: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 14 | 15 | def f(x): | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 10 10 | print(f'Hello {dict((x,x) for x in "abc")} World') @@ -206,7 +205,7 @@ C402.py:13:5: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 15 15 | def f(x): 16 16 | return x -C402.py:13:38: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:13:38: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 12 | f'{dict((x, x) for x in range(3)) | dict((x, x) for x in range(3))}' 13 | f'{ dict((x, x) for x in range(3)) | dict((x, x) for x in range(3)) }' @@ -214,7 +213,7 @@ C402.py:13:38: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension 14 | 15 | def f(x): | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 10 10 | print(f'Hello {dict((x,x) for x in "abc")} World') @@ -226,7 +225,7 @@ C402.py:13:38: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension 15 15 | def f(x): 16 16 | return x -C402.py:18:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:18:16: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 16 | return x 17 | @@ -235,7 +234,7 @@ C402.py:18:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension 19 | 20 | # Regression test for: https://github.com/astral-sh/ruff/issues/7086 | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 15 15 | def f(x): @@ -247,7 +246,7 @@ C402.py:18:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension 20 20 | # Regression test for: https://github.com/astral-sh/ruff/issues/7086 21 21 | dict((k,v)for k,v in d.iteritems() if k in only_args) -C402.py:21:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) +C402.py:21:1: C402 [*] Unnecessary generator (rewrite as a dict comprehension) | 20 | # Regression test for: https://github.com/astral-sh/ruff/issues/7086 21 | dict((k,v)for k,v in d.iteritems() if k in only_args) @@ -255,7 +254,7 @@ C402.py:21:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) 22 | 23 | # Regression test for: https://github.com/astral-sh/ruff/issues/7455#issuecomment-1722458940 | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 18 18 | print(f'Hello {dict((x,f(x)) for x in "abc")} World') diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C403_C403.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C403_C403.py.snap index c99c1114392b1..513dabb532005 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C403_C403.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C403_C403.py.snap @@ -1,15 +1,14 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C403.py:1:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:1:5: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 1 | s = set([x for x in range(3)]) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ C403 2 | s = set( 3 | [x for x in range(3)] | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 1 |-s = set([x for x in range(3)]) @@ -18,7 +17,7 @@ C403.py:1:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr 3 3 | [x for x in range(3)] 4 4 | ) -C403.py:2:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:2:5: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 1 | s = set([x for x in range(3)]) 2 | s = set( @@ -29,7 +28,7 @@ C403.py:2:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr 5 | 6 | s = f"{set([x for x in 'ab'])}" | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 1 1 | s = set([x for x in range(3)]) @@ -43,7 +42,7 @@ C403.py:2:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr 6 6 | s = f"{set([x for x in 'ab'])}" 7 7 | s = f'{set([x for x in "ab"])}' -C403.py:6:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:6:8: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 4 | ) 5 | @@ -51,7 +50,7 @@ C403.py:6:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr | ^^^^^^^^^^^^^^^^^^^^^^ C403 7 | s = f'{set([x for x in "ab"])}' | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 3 3 | [x for x in range(3)] @@ -63,7 +62,7 @@ C403.py:6:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr 8 8 | 9 9 | def f(x): -C403.py:7:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:7:8: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 6 | s = f"{set([x for x in 'ab'])}" 7 | s = f'{set([x for x in "ab"])}' @@ -71,7 +70,7 @@ C403.py:7:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr 8 | 9 | def f(x): | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 4 4 | ) @@ -83,7 +82,7 @@ C403.py:7:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr 9 9 | def f(x): 10 10 | return x -C403.py:12:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:12:8: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 10 | return x 11 | @@ -92,7 +91,7 @@ C403.py:12:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp 13 | 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }" | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 9 9 | def f(x): @@ -104,7 +103,7 @@ C403.py:12:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp 14 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }" 15 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}" -C403.py:14:9: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:14:9: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 12 | s = f"{set([f(x) for x in 'ab'])}" 13 | @@ -112,7 +111,7 @@ C403.py:14:9: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp | ^^^^^^^^^^^^^^^^^^^^^^ C403 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}" | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 11 11 | @@ -124,7 +123,7 @@ C403.py:14:9: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp 16 16 | 17 17 | s = set( # comment -C403.py:14:34: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:14:34: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 12 | s = f"{set([f(x) for x in 'ab'])}" 13 | @@ -132,7 +131,7 @@ C403.py:14:34: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` com | ^^^^^^^^^^^^^^^^^^^^^^ C403 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}" | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 11 11 | @@ -144,7 +143,7 @@ C403.py:14:34: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` com 16 16 | 17 17 | s = set( # comment -C403.py:15:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:15:8: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }" 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}" @@ -152,7 +151,7 @@ C403.py:15:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp 16 | 17 | s = set( # comment | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 12 12 | s = f"{set([f(x) for x in 'ab'])}" @@ -164,7 +163,7 @@ C403.py:15:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp 17 17 | s = set( # comment 18 18 | [x for x in range(3)] -C403.py:15:33: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:15:33: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }" 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}" @@ -172,7 +171,7 @@ C403.py:15:33: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` com 16 | 17 | s = set( # comment | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 12 12 | s = f"{set([f(x) for x in 'ab'])}" @@ -184,7 +183,7 @@ C403.py:15:33: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` com 17 17 | s = set( # comment 18 18 | [x for x in range(3)] -C403.py:17:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:17:5: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}" 16 | @@ -196,7 +195,7 @@ C403.py:17:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp 20 | 21 | s = set([ # comment | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 14 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }" @@ -212,7 +211,7 @@ C403.py:17:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp 21 21 | s = set([ # comment 22 22 | x for x in range(3) -C403.py:21:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) +C403.py:21:5: C403 [*] Unnecessary list comprehension (rewrite as a set comprehension) | 19 | ) 20 | @@ -222,7 +221,7 @@ C403.py:21:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp 23 | | ]) | |__^ C403 | - = help: Rewrite as a `set` comprehension + = help: Rewrite as a set comprehension ℹ Unsafe fix 18 18 | [x for x in range(3)] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C404_C404.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C404_C404.py.snap index ef18d2a26b254..cfea193b1c6cd 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C404_C404.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C404_C404.py.snap @@ -1,14 +1,13 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C404.py:1:1: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:1:1: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 1 | dict([(i, i) for i in range(3)]) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C404 2 | dict([(i, i) for i in range(3)], z=4) | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 1 |-dict([(i, i) for i in range(3)]) @@ -17,7 +16,7 @@ C404.py:1:1: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp 3 3 | 4 4 | def f(x): -C404.py:7:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:7:4: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 5 | return x 6 | @@ -26,7 +25,7 @@ C404.py:7:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp 8 | f"{dict([(s,s) for s in 'ab'])}" 9 | f"{dict([(s, s) for s in 'ab'])}" | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 4 4 | def f(x): @@ -38,7 +37,7 @@ C404.py:7:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp 9 9 | f"{dict([(s, s) for s in 'ab'])}" 10 10 | f"{dict([(s,f(s)) for s in 'ab'])}" -C404.py:8:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:8:4: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 7 | f'{dict([(s,s) for s in "ab"])}' 8 | f"{dict([(s,s) for s in 'ab'])}" @@ -46,7 +45,7 @@ C404.py:8:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp 9 | f"{dict([(s, s) for s in 'ab'])}" 10 | f"{dict([(s,f(s)) for s in 'ab'])}" | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 5 5 | return x @@ -58,7 +57,7 @@ C404.py:8:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp 10 10 | f"{dict([(s,f(s)) for s in 'ab'])}" 11 11 | -C404.py:9:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:9:4: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 7 | f'{dict([(s,s) for s in "ab"])}' 8 | f"{dict([(s,s) for s in 'ab'])}" @@ -66,7 +65,7 @@ C404.py:9:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C404 10 | f"{dict([(s,f(s)) for s in 'ab'])}" | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 6 6 | @@ -78,7 +77,7 @@ C404.py:9:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp 11 11 | 12 12 | f'{dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"])}' -C404.py:10:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:10:4: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 8 | f"{dict([(s,s) for s in 'ab'])}" 9 | f"{dict([(s, s) for s in 'ab'])}" @@ -87,7 +86,7 @@ C404.py:10:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com 11 | 12 | f'{dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"])}' | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 7 7 | f'{dict([(s,s) for s in "ab"])}' @@ -99,7 +98,7 @@ C404.py:10:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com 12 12 | f'{dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"])}' 13 13 | f'{ dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"]) }' -C404.py:12:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:12:4: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 10 | f"{dict([(s,f(s)) for s in 'ab'])}" 11 | @@ -107,7 +106,7 @@ C404.py:12:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ C404 13 | f'{ dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"]) }' | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 9 9 | f"{dict([(s, s) for s in 'ab'])}" @@ -119,7 +118,7 @@ C404.py:12:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com 14 14 | 15 15 | # Regression test for: https://github.com/astral-sh/ruff/issues/7087 -C404.py:12:34: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:12:34: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 10 | f"{dict([(s,f(s)) for s in 'ab'])}" 11 | @@ -127,7 +126,7 @@ C404.py:12:34: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` co | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ C404 13 | f'{ dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"]) }' | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 9 9 | f"{dict([(s, s) for s in 'ab'])}" @@ -139,7 +138,7 @@ C404.py:12:34: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` co 14 14 | 15 15 | # Regression test for: https://github.com/astral-sh/ruff/issues/7087 -C404.py:13:5: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:13:5: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 12 | f'{dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"])}' 13 | f'{ dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"]) }' @@ -147,7 +146,7 @@ C404.py:13:5: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com 14 | 15 | # Regression test for: https://github.com/astral-sh/ruff/issues/7087 | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 10 10 | f"{dict([(s,f(s)) for s in 'ab'])}" @@ -159,7 +158,7 @@ C404.py:13:5: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com 15 15 | # Regression test for: https://github.com/astral-sh/ruff/issues/7087 16 16 | saved.append(dict([(k, v)for k,v in list(unique_instance.__dict__.items()) if k in [f.name for f in unique_instance._meta.fields]])) -C404.py:13:35: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:13:35: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 12 | f'{dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"])}' 13 | f'{ dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"]) }' @@ -167,7 +166,7 @@ C404.py:13:35: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` co 14 | 15 | # Regression test for: https://github.com/astral-sh/ruff/issues/7087 | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 10 10 | f"{dict([(s,f(s)) for s in 'ab'])}" @@ -179,13 +178,13 @@ C404.py:13:35: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` co 15 15 | # Regression test for: https://github.com/astral-sh/ruff/issues/7087 16 16 | saved.append(dict([(k, v)for k,v in list(unique_instance.__dict__.items()) if k in [f.name for f in unique_instance._meta.fields]])) -C404.py:16:14: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) +C404.py:16:14: C404 [*] Unnecessary list comprehension (rewrite as a dict comprehension) | 15 | # Regression test for: https://github.com/astral-sh/ruff/issues/7087 16 | saved.append(dict([(k, v)for k,v in list(unique_instance.__dict__.items()) if k in [f.name for f in unique_instance._meta.fields]])) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C404 | - = help: Rewrite as a `dict` comprehension + = help: Rewrite as a dict comprehension ℹ Unsafe fix 13 13 | f'{ dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"]) }' diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C405_C405.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C405_C405.py.snap index 1f5c279905067..59d160bdc2483 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C405_C405.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C405_C405.py.snap @@ -1,15 +1,14 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C405.py:1:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:1:1: C405 [*] Unnecessary list literal (rewrite as a set literal) | 1 | set([1, 2]) | ^^^^^^^^^^^ C405 2 | set((1, 2)) 3 | set([]) | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 1 |-set([1, 2]) @@ -18,7 +17,7 @@ C405.py:1:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 3 3 | set([]) 4 4 | set(()) -C405.py:2:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) +C405.py:2:1: C405 [*] Unnecessary tuple literal (rewrite as a set literal) | 1 | set([1, 2]) 2 | set((1, 2)) @@ -26,7 +25,7 @@ C405.py:2:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 3 | set([]) 4 | set(()) | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 1 1 | set([1, 2]) @@ -36,7 +35,7 @@ C405.py:2:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 4 4 | set(()) 5 5 | set() -C405.py:3:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:3:1: C405 [*] Unnecessary list literal (rewrite as a set literal) | 1 | set([1, 2]) 2 | set((1, 2)) @@ -45,7 +44,7 @@ C405.py:3:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 4 | set(()) 5 | set() | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 1 1 | set([1, 2]) @@ -56,7 +55,7 @@ C405.py:3:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 5 5 | set() 6 6 | set((1,)) -C405.py:4:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) +C405.py:4:1: C405 [*] Unnecessary tuple literal (rewrite as a set literal) | 2 | set((1, 2)) 3 | set([]) @@ -65,7 +64,7 @@ C405.py:4:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 5 | set() 6 | set((1,)) | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 1 1 | set([1, 2]) @@ -78,7 +77,7 @@ C405.py:4:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 7 7 | set(( 8 8 | 1, -C405.py:6:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) +C405.py:6:1: C405 [*] Unnecessary tuple literal (rewrite as a set literal) | 4 | set(()) 5 | set() @@ -87,7 +86,7 @@ C405.py:6:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 7 | set(( 8 | 1, | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 3 3 | set([]) @@ -99,7 +98,7 @@ C405.py:6:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 8 8 | 1, 9 9 | )) -C405.py:7:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) +C405.py:7:1: C405 [*] Unnecessary tuple literal (rewrite as a set literal) | 5 | set() 6 | set((1,)) @@ -110,7 +109,7 @@ C405.py:7:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 10 | set([ 11 | 1, | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 4 4 | set(()) @@ -125,7 +124,7 @@ C405.py:7:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 11 11 | 1, 12 12 | ]) -C405.py:10:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:10:1: C405 [*] Unnecessary list literal (rewrite as a set literal) | 8 | 1, 9 | )) @@ -136,7 +135,7 @@ C405.py:10:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 13 | set( 14 | (1,) | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 7 7 | set(( @@ -151,7 +150,7 @@ C405.py:10:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 14 14 | (1,) 15 15 | ) -C405.py:13:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) +C405.py:13:1: C405 [*] Unnecessary tuple literal (rewrite as a set literal) | 11 | 1, 12 | ]) @@ -162,7 +161,7 @@ C405.py:13:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 16 | set( 17 | [1,] | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 10 10 | set([ @@ -176,7 +175,7 @@ C405.py:13:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) 17 15 | [1,] 18 16 | ) -C405.py:16:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:16:1: C405 [*] Unnecessary list literal (rewrite as a set literal) | 14 | (1,) 15 | ) @@ -187,7 +186,7 @@ C405.py:16:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 19 | f"{set([1,2,3])}" 20 | f"{set(['a', 'b'])}" | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 13 13 | set( @@ -201,7 +200,7 @@ C405.py:16:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 20 18 | f"{set(['a', 'b'])}" 21 19 | f'{set(["a", "b"])}' -C405.py:19:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:19:4: C405 [*] Unnecessary list literal (rewrite as a set literal) | 17 | [1,] 18 | ) @@ -210,7 +209,7 @@ C405.py:19:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 20 | f"{set(['a', 'b'])}" 21 | f'{set(["a", "b"])}' | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 16 16 | set( @@ -222,7 +221,7 @@ C405.py:19:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 21 21 | f'{set(["a", "b"])}' 22 22 | -C405.py:20:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:20:4: C405 [*] Unnecessary list literal (rewrite as a set literal) | 18 | ) 19 | f"{set([1,2,3])}" @@ -230,7 +229,7 @@ C405.py:20:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) | ^^^^^^^^^^^^^^^ C405 21 | f'{set(["a", "b"])}' | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 17 17 | [1,] @@ -242,7 +241,7 @@ C405.py:20:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 22 22 | 23 23 | f"{set(['a', 'b']) - set(['a'])}" -C405.py:21:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:21:4: C405 [*] Unnecessary list literal (rewrite as a set literal) | 19 | f"{set([1,2,3])}" 20 | f"{set(['a', 'b'])}" @@ -251,7 +250,7 @@ C405.py:21:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 22 | 23 | f"{set(['a', 'b']) - set(['a'])}" | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 18 18 | ) @@ -263,7 +262,7 @@ C405.py:21:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 23 23 | f"{set(['a', 'b']) - set(['a'])}" 24 24 | f"{ set(['a', 'b']) - set(['a']) }" -C405.py:23:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:23:4: C405 [*] Unnecessary list literal (rewrite as a set literal) | 21 | f'{set(["a", "b"])}' 22 | @@ -272,7 +271,7 @@ C405.py:23:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 24 | f"{ set(['a', 'b']) - set(['a']) }" 25 | f"a {set(['a', 'b']) - set(['a'])} b" | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 20 20 | f"{set(['a', 'b'])}" @@ -284,7 +283,7 @@ C405.py:23:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 25 25 | f"a {set(['a', 'b']) - set(['a'])} b" 26 26 | f"a { set(['a', 'b']) - set(['a']) } b" -C405.py:23:22: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:23:22: C405 [*] Unnecessary list literal (rewrite as a set literal) | 21 | f'{set(["a", "b"])}' 22 | @@ -293,7 +292,7 @@ C405.py:23:22: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 24 | f"{ set(['a', 'b']) - set(['a']) }" 25 | f"a {set(['a', 'b']) - set(['a'])} b" | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 20 20 | f"{set(['a', 'b'])}" @@ -305,7 +304,7 @@ C405.py:23:22: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 25 25 | f"a {set(['a', 'b']) - set(['a'])} b" 26 26 | f"a { set(['a', 'b']) - set(['a']) } b" -C405.py:24:5: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:24:5: C405 [*] Unnecessary list literal (rewrite as a set literal) | 23 | f"{set(['a', 'b']) - set(['a'])}" 24 | f"{ set(['a', 'b']) - set(['a']) }" @@ -313,7 +312,7 @@ C405.py:24:5: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 25 | f"a {set(['a', 'b']) - set(['a'])} b" 26 | f"a { set(['a', 'b']) - set(['a']) } b" | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 21 21 | f'{set(["a", "b"])}' @@ -324,7 +323,7 @@ C405.py:24:5: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 25 25 | f"a {set(['a', 'b']) - set(['a'])} b" 26 26 | f"a { set(['a', 'b']) - set(['a']) } b" -C405.py:24:23: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:24:23: C405 [*] Unnecessary list literal (rewrite as a set literal) | 23 | f"{set(['a', 'b']) - set(['a'])}" 24 | f"{ set(['a', 'b']) - set(['a']) }" @@ -332,7 +331,7 @@ C405.py:24:23: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 25 | f"a {set(['a', 'b']) - set(['a'])} b" 26 | f"a { set(['a', 'b']) - set(['a']) } b" | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 21 21 | f'{set(["a", "b"])}' @@ -343,7 +342,7 @@ C405.py:24:23: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 25 25 | f"a {set(['a', 'b']) - set(['a'])} b" 26 26 | f"a { set(['a', 'b']) - set(['a']) } b" -C405.py:25:6: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:25:6: C405 [*] Unnecessary list literal (rewrite as a set literal) | 23 | f"{set(['a', 'b']) - set(['a'])}" 24 | f"{ set(['a', 'b']) - set(['a']) }" @@ -351,7 +350,7 @@ C405.py:25:6: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) | ^^^^^^^^^^^^^^^ C405 26 | f"a { set(['a', 'b']) - set(['a']) } b" | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 22 22 | @@ -361,7 +360,7 @@ C405.py:25:6: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 25 |+f"a { {'a', 'b'} - set(['a'])} b" 26 26 | f"a { set(['a', 'b']) - set(['a']) } b" -C405.py:25:24: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:25:24: C405 [*] Unnecessary list literal (rewrite as a set literal) | 23 | f"{set(['a', 'b']) - set(['a'])}" 24 | f"{ set(['a', 'b']) - set(['a']) }" @@ -369,7 +368,7 @@ C405.py:25:24: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) | ^^^^^^^^^^ C405 26 | f"a { set(['a', 'b']) - set(['a']) } b" | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 22 22 | @@ -379,14 +378,14 @@ C405.py:25:24: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 25 |+f"a {set(['a', 'b']) - {'a'} } b" 26 26 | f"a { set(['a', 'b']) - set(['a']) } b" -C405.py:26:7: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:26:7: C405 [*] Unnecessary list literal (rewrite as a set literal) | 24 | f"{ set(['a', 'b']) - set(['a']) }" 25 | f"a {set(['a', 'b']) - set(['a'])} b" 26 | f"a { set(['a', 'b']) - set(['a']) } b" | ^^^^^^^^^^^^^^^ C405 | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 23 23 | f"{set(['a', 'b']) - set(['a'])}" @@ -395,14 +394,14 @@ C405.py:26:7: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) 26 |-f"a { set(['a', 'b']) - set(['a']) } b" 26 |+f"a { {'a', 'b'} - set(['a']) } b" -C405.py:26:25: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) +C405.py:26:25: C405 [*] Unnecessary list literal (rewrite as a set literal) | 24 | f"{ set(['a', 'b']) - set(['a']) }" 25 | f"a {set(['a', 'b']) - set(['a'])} b" 26 | f"a { set(['a', 'b']) - set(['a']) } b" | ^^^^^^^^^^ C405 | - = help: Rewrite as a `set` literal + = help: Rewrite as a set literal ℹ Unsafe fix 23 23 | f"{set(['a', 'b']) - set(['a'])}" diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C406_C406.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C406_C406.py.snap index 4996ca8eaa622..c8a3853bc18b2 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C406_C406.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C406_C406.py.snap @@ -1,15 +1,14 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C406.py:1:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal) +C406.py:1:6: C406 [*] Unnecessary list literal (rewrite as a dict literal) | 1 | d1 = dict([(1, 2)]) | ^^^^^^^^^^^^^^ C406 2 | d2 = dict(((1, 2),)) 3 | d3 = dict([]) | - = help: Rewrite as a `dict` literal + = help: Rewrite as a dict literal ℹ Unsafe fix 1 |-d1 = dict([(1, 2)]) @@ -18,7 +17,7 @@ C406.py:1:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal) 3 3 | d3 = dict([]) 4 4 | d4 = dict(()) -C406.py:2:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal) +C406.py:2:6: C406 [*] Unnecessary tuple literal (rewrite as a dict literal) | 1 | d1 = dict([(1, 2)]) 2 | d2 = dict(((1, 2),)) @@ -26,7 +25,7 @@ C406.py:2:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal) 3 | d3 = dict([]) 4 | d4 = dict(()) | - = help: Rewrite as a `dict` literal + = help: Rewrite as a dict literal ℹ Unsafe fix 1 1 | d1 = dict([(1, 2)]) @@ -36,7 +35,7 @@ C406.py:2:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal) 4 4 | d4 = dict(()) 5 5 | d5 = dict() -C406.py:3:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal) +C406.py:3:6: C406 [*] Unnecessary list literal (rewrite as a dict literal) | 1 | d1 = dict([(1, 2)]) 2 | d2 = dict(((1, 2),)) @@ -45,7 +44,7 @@ C406.py:3:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal) 4 | d4 = dict(()) 5 | d5 = dict() | - = help: Rewrite as a `dict` literal + = help: Rewrite as a dict literal ℹ Unsafe fix 1 1 | d1 = dict([(1, 2)]) @@ -55,7 +54,7 @@ C406.py:3:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal) 4 4 | d4 = dict(()) 5 5 | d5 = dict() -C406.py:4:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal) +C406.py:4:6: C406 [*] Unnecessary tuple literal (rewrite as a dict literal) | 2 | d2 = dict(((1, 2),)) 3 | d3 = dict([]) @@ -63,7 +62,7 @@ C406.py:4:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal) | ^^^^^^^^ C406 5 | d5 = dict() | - = help: Rewrite as a `dict` literal + = help: Rewrite as a dict literal ℹ Unsafe fix 1 1 | d1 = dict([(1, 2)]) diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C408_C408.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C408_C408.py.snap index 062f242ca0d18..8e2f993e3f55f 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C408_C408.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C408_C408.py.snap @@ -1,8 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C408.py:1:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal) +C408.py:1:5: C408 [*] Unnecessary `tuple()` call (rewrite as a literal) | 1 | t = tuple() | ^^^^^^^ C408 @@ -18,7 +17,7 @@ C408.py:1:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal) 3 3 | d1 = dict() 4 4 | d2 = dict(a=1) -C408.py:2:5: C408 [*] Unnecessary `list` call (rewrite as a literal) +C408.py:2:5: C408 [*] Unnecessary `list()` call (rewrite as a literal) | 1 | t = tuple() 2 | l = list() @@ -36,7 +35,7 @@ C408.py:2:5: C408 [*] Unnecessary `list` call (rewrite as a literal) 4 4 | d2 = dict(a=1) 5 5 | d3 = dict(**d2) -C408.py:3:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:3:6: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 1 | t = tuple() 2 | l = list() @@ -56,7 +55,7 @@ C408.py:3:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) 5 5 | d3 = dict(**d2) 6 6 | -C408.py:4:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:4:6: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 2 | l = list() 3 | d1 = dict() @@ -76,7 +75,7 @@ C408.py:4:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) 6 6 | 7 7 | -C408.py:14:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:14:4: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 12 | a = list() 13 | @@ -97,7 +96,7 @@ C408.py:14:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) 16 16 | f"{dict()}" 17 17 | f"a {dict()} b" -C408.py:15:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:15:4: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 14 | f"{dict(x='y')}" 15 | f'{dict(x="y")}' @@ -117,7 +116,7 @@ C408.py:15:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) 17 17 | f"a {dict()} b" 18 18 | -C408.py:16:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:16:4: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 14 | f"{dict(x='y')}" 15 | f'{dict(x="y")}' @@ -137,7 +136,7 @@ C408.py:16:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) 18 18 | 19 19 | f"{dict(x='y') | dict(y='z')}" -C408.py:17:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:17:6: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 15 | f'{dict(x="y")}' 16 | f"{dict()}" @@ -158,7 +157,7 @@ C408.py:17:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) 19 19 | f"{dict(x='y') | dict(y='z')}" 20 20 | f"{ dict(x='y') | dict(y='z') }" -C408.py:19:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:19:4: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 17 | f"a {dict()} b" 18 | @@ -179,7 +178,7 @@ C408.py:19:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) 21 21 | f"a {dict(x='y') | dict(y='z')} b" 22 22 | f"a { dict(x='y') | dict(y='z') } b" -C408.py:19:18: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:19:18: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 17 | f"a {dict()} b" 18 | @@ -200,7 +199,7 @@ C408.py:19:18: C408 [*] Unnecessary `dict` call (rewrite as a literal) 21 21 | f"a {dict(x='y') | dict(y='z')} b" 22 22 | f"a { dict(x='y') | dict(y='z') } b" -C408.py:20:5: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:20:5: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 19 | f"{dict(x='y') | dict(y='z')}" 20 | f"{ dict(x='y') | dict(y='z') }" @@ -220,7 +219,7 @@ C408.py:20:5: C408 [*] Unnecessary `dict` call (rewrite as a literal) 22 22 | f"a { dict(x='y') | dict(y='z') } b" 23 23 | -C408.py:20:19: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:20:19: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 19 | f"{dict(x='y') | dict(y='z')}" 20 | f"{ dict(x='y') | dict(y='z') }" @@ -240,7 +239,7 @@ C408.py:20:19: C408 [*] Unnecessary `dict` call (rewrite as a literal) 22 22 | f"a { dict(x='y') | dict(y='z') } b" 23 23 | -C408.py:21:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:21:6: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 19 | f"{dict(x='y') | dict(y='z')}" 20 | f"{ dict(x='y') | dict(y='z') }" @@ -260,7 +259,7 @@ C408.py:21:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) 23 23 | 24 24 | dict( -C408.py:21:20: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:21:20: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 19 | f"{dict(x='y') | dict(y='z')}" 20 | f"{ dict(x='y') | dict(y='z') }" @@ -280,7 +279,7 @@ C408.py:21:20: C408 [*] Unnecessary `dict` call (rewrite as a literal) 23 23 | 24 24 | dict( -C408.py:22:7: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:22:7: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 20 | f"{ dict(x='y') | dict(y='z') }" 21 | f"a {dict(x='y') | dict(y='z')} b" @@ -301,7 +300,7 @@ C408.py:22:7: C408 [*] Unnecessary `dict` call (rewrite as a literal) 24 24 | dict( 25 25 | # comment -C408.py:22:21: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:22:21: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 20 | f"{ dict(x='y') | dict(y='z') }" 21 | f"a {dict(x='y') | dict(y='z')} b" @@ -322,7 +321,7 @@ C408.py:22:21: C408 [*] Unnecessary `dict` call (rewrite as a literal) 24 24 | dict( 25 25 | # comment -C408.py:24:1: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:24:1: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 22 | f"a { dict(x='y') | dict(y='z') } b" 23 | @@ -348,7 +347,7 @@ C408.py:24:1: C408 [*] Unnecessary `dict` call (rewrite as a literal) 28 28 | tuple( # comment 29 29 | ) -C408.py:28:1: C408 [*] Unnecessary `tuple` call (rewrite as a literal) +C408.py:28:1: C408 [*] Unnecessary `tuple()` call (rewrite as a literal) | 26 | ) 27 | diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C408_C408.py_allow_dict_calls_with_keyword_arguments.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C408_C408.py_allow_dict_calls_with_keyword_arguments.snap index 08c15b04f3e75..8e979ae7eceb0 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C408_C408.py_allow_dict_calls_with_keyword_arguments.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C408_C408.py_allow_dict_calls_with_keyword_arguments.snap @@ -1,8 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C408.py:1:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal) +C408.py:1:5: C408 [*] Unnecessary `tuple()` call (rewrite as a literal) | 1 | t = tuple() | ^^^^^^^ C408 @@ -18,7 +17,7 @@ C408.py:1:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal) 3 3 | d1 = dict() 4 4 | d2 = dict(a=1) -C408.py:2:5: C408 [*] Unnecessary `list` call (rewrite as a literal) +C408.py:2:5: C408 [*] Unnecessary `list()` call (rewrite as a literal) | 1 | t = tuple() 2 | l = list() @@ -36,7 +35,7 @@ C408.py:2:5: C408 [*] Unnecessary `list` call (rewrite as a literal) 4 4 | d2 = dict(a=1) 5 5 | d3 = dict(**d2) -C408.py:3:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:3:6: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 1 | t = tuple() 2 | l = list() @@ -56,7 +55,7 @@ C408.py:3:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) 5 5 | d3 = dict(**d2) 6 6 | -C408.py:16:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:16:4: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 14 | f"{dict(x='y')}" 15 | f'{dict(x="y")}' @@ -76,7 +75,7 @@ C408.py:16:4: C408 [*] Unnecessary `dict` call (rewrite as a literal) 18 18 | 19 19 | f"{dict(x='y') | dict(y='z')}" -C408.py:17:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:17:6: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 15 | f'{dict(x="y")}' 16 | f"{dict()}" @@ -97,7 +96,7 @@ C408.py:17:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) 19 19 | f"{dict(x='y') | dict(y='z')}" 20 20 | f"{ dict(x='y') | dict(y='z') }" -C408.py:24:1: C408 [*] Unnecessary `dict` call (rewrite as a literal) +C408.py:24:1: C408 [*] Unnecessary `dict()` call (rewrite as a literal) | 22 | f"a { dict(x='y') | dict(y='z') } b" 23 | @@ -123,7 +122,7 @@ C408.py:24:1: C408 [*] Unnecessary `dict` call (rewrite as a literal) 28 28 | tuple( # comment 29 29 | ) -C408.py:28:1: C408 [*] Unnecessary `tuple` call (rewrite as a literal) +C408.py:28:1: C408 [*] Unnecessary `tuple()` call (rewrite as a literal) | 26 | ) 27 | diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C409_C409.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C409_C409.py.snap index a03c88e69d64c..b432b42187d35 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C409_C409.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C409_C409.py.snap @@ -1,15 +1,14 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C409.py:1:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:1:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 1 | t1 = tuple([]) | ^^^^^^^^^ C409 2 | t2 = tuple([1, 2]) 3 | t3 = tuple((1, 2)) | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 1 |-t1 = tuple([]) @@ -18,7 +17,7 @@ C409.py:1:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 3 3 | t3 = tuple((1, 2)) 4 4 | t4 = tuple([ -C409.py:2:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:2:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 1 | t1 = tuple([]) 2 | t2 = tuple([1, 2]) @@ -26,7 +25,7 @@ C409.py:2:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 3 | t3 = tuple((1, 2)) 4 | t4 = tuple([ | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 1 1 | t1 = tuple([]) @@ -36,7 +35,7 @@ C409.py:2:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 4 4 | t4 = tuple([ 5 5 | 1, -C409.py:3:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) +C409.py:3:6: C409 [*] Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`) | 1 | t1 = tuple([]) 2 | t2 = tuple([1, 2]) @@ -56,7 +55,7 @@ C409.py:3:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove th 5 5 | 1, 6 6 | 2 -C409.py:4:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:4:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 2 | t2 = tuple([1, 2]) 3 | t3 = tuple((1, 2)) @@ -69,7 +68,7 @@ C409.py:4:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 8 | t5 = tuple( 9 | (1, 2) | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 1 1 | t1 = tuple([]) @@ -85,7 +84,7 @@ C409.py:4:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 9 9 | (1, 2) 10 10 | ) -C409.py:8:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) +C409.py:8:6: C409 [*] Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`) | 6 | 2 7 | ]) @@ -111,7 +110,7 @@ C409.py:8:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove th 12 10 | tuple( # comment 13 11 | [1, 2] -C409.py:12:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:12:1: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 10 | ) 11 | @@ -122,7 +121,7 @@ C409.py:12:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 15 | 16 | tuple([ # comment | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 9 9 | (1, 2) @@ -136,7 +135,7 @@ C409.py:12:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 16 14 | tuple([ # comment 17 15 | 1, 2 -C409.py:16:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:16:1: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 14 | ) 15 | @@ -147,7 +146,7 @@ C409.py:16:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 19 | 20 | tuple(( | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 13 13 | [1, 2] @@ -162,7 +161,7 @@ C409.py:16:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 20 20 | tuple(( 21 21 | 1, -C409.py:20:1: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) +C409.py:20:1: C409 [*] Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`) | 18 | ]) 19 | @@ -188,7 +187,7 @@ C409.py:20:1: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove t 24 24 | t6 = tuple([1]) 25 25 | t7 = tuple((1,)) -C409.py:24:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:24:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 22 | )) 23 | @@ -197,7 +196,7 @@ C409.py:24:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 25 | t7 = tuple((1,)) 26 | t8 = tuple([1,]) | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 21 21 | 1, @@ -209,7 +208,7 @@ C409.py:24:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 26 26 | t8 = tuple([1,]) 27 27 | -C409.py:25:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) +C409.py:25:6: C409 [*] Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`) | 24 | t6 = tuple([1]) 25 | t7 = tuple((1,)) @@ -228,7 +227,7 @@ C409.py:25:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove t 27 27 | 28 28 | tuple([x for x in range(5)]) -C409.py:26:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:26:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 24 | t6 = tuple([1]) 25 | t7 = tuple((1,)) @@ -237,7 +236,7 @@ C409.py:26:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 27 | 28 | tuple([x for x in range(5)]) | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 23 23 | diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C410_C410.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C410_C410.py.snap index 05d007f36c772..f33a4ed1ffd2f 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C410_C410.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C410_C410.py.snap @@ -1,15 +1,14 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C410.py:1:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the outer call to `list()`) +C410.py:1:6: C410 [*] Unnecessary list literal passed to `list()` (remove the outer call to `list()`) | 1 | l1 = list([1, 2]) | ^^^^^^^^^^^^ C410 2 | l2 = list((1, 2)) 3 | l3 = list([]) | - = help: Remove outer `list` call + = help: Remove outer `list()` call ℹ Unsafe fix 1 |-l1 = list([1, 2]) @@ -18,7 +17,7 @@ C410.py:1:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the 3 3 | l3 = list([]) 4 4 | l4 = list(()) -C410.py:2:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as a `list` literal) +C410.py:2:6: C410 [*] Unnecessary tuple literal passed to `list()` (rewrite as a single list literal) | 1 | l1 = list([1, 2]) 2 | l2 = list((1, 2)) @@ -26,7 +25,7 @@ C410.py:2:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as 3 | l3 = list([]) 4 | l4 = list(()) | - = help: Rewrite as a `list` literal + = help: Rewrite as a single list literal ℹ Unsafe fix 1 1 | l1 = list([1, 2]) @@ -36,7 +35,7 @@ C410.py:2:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as 4 4 | l4 = list(()) 5 5 | -C410.py:3:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the outer call to `list()`) +C410.py:3:6: C410 [*] Unnecessary list literal passed to `list()` (remove the outer call to `list()`) | 1 | l1 = list([1, 2]) 2 | l2 = list((1, 2)) @@ -44,7 +43,7 @@ C410.py:3:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the | ^^^^^^^^ C410 4 | l4 = list(()) | - = help: Remove outer `list` call + = help: Remove outer `list()` call ℹ Unsafe fix 1 1 | l1 = list([1, 2]) @@ -55,14 +54,14 @@ C410.py:3:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the 5 5 | 6 6 | -C410.py:4:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as a `list` literal) +C410.py:4:6: C410 [*] Unnecessary tuple literal passed to `list()` (rewrite as a single list literal) | 2 | l2 = list((1, 2)) 3 | l3 = list([]) 4 | l4 = list(()) | ^^^^^^^^ C410 | - = help: Rewrite as a `list` literal + = help: Rewrite as a single list literal ℹ Unsafe fix 1 1 | l1 = list([1, 2]) @@ -74,7 +73,7 @@ C410.py:4:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as 6 6 | 7 7 | list( # comment -C410.py:7:1: C410 [*] Unnecessary `list` literal passed to `list()` (remove the outer call to `list()`) +C410.py:7:1: C410 [*] Unnecessary list literal passed to `list()` (remove the outer call to `list()`) | 7 | / list( # comment 8 | | [1, 2] @@ -83,7 +82,7 @@ C410.py:7:1: C410 [*] Unnecessary `list` literal passed to `list()` (remove the 10 | 11 | list([ # comment | - = help: Remove outer `list` call + = help: Remove outer `list()` call ℹ Unsafe fix 4 4 | l4 = list(()) @@ -97,7 +96,7 @@ C410.py:7:1: C410 [*] Unnecessary `list` literal passed to `list()` (remove the 11 9 | list([ # comment 12 10 | 1, 2 -C410.py:11:1: C410 [*] Unnecessary `list` literal passed to `list()` (remove the outer call to `list()`) +C410.py:11:1: C410 [*] Unnecessary list literal passed to `list()` (remove the outer call to `list()`) | 9 | ) 10 | @@ -106,7 +105,7 @@ C410.py:11:1: C410 [*] Unnecessary `list` literal passed to `list()` (remove the 13 | | ]) | |__^ C410 | - = help: Remove outer `list` call + = help: Remove outer `list()` call ℹ Unsafe fix 8 8 | [1, 2] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C411_C411.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C411_C411.py.snap index bcab68af1f971..16d2a3c61c605 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C411_C411.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C411_C411.py.snap @@ -1,14 +1,13 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C411.py:2:1: C411 [*] Unnecessary `list` call (remove the outer call to `list()`) +C411.py:2:1: C411 [*] Unnecessary `list()` call (remove the outer call to `list()`) | 1 | x = [1, 2, 3] 2 | list([i for i in x]) | ^^^^^^^^^^^^^^^^^^^^ C411 | - = help: Remove outer `list` call + = help: Remove outer `list()` call ℹ Unsafe fix 1 1 | x = [1, 2, 3] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C413_C413.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C413_C413.py.snap index 4335608a351a6..67c6d81d1ffec 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C413_C413.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C413_C413.py.snap @@ -1,8 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C413.py:3:1: C413 [*] Unnecessary `list` call around `sorted()` +C413.py:3:1: C413 [*] Unnecessary `list()` call around `sorted()` | 1 | x = [2, 3, 1] 2 | list(x) @@ -11,7 +10,7 @@ C413.py:3:1: C413 [*] Unnecessary `list` call around `sorted()` 4 | reversed(sorted(x)) 5 | reversed(sorted(x, key=lambda e: e)) | - = help: Remove unnecessary `list` call + = help: Remove unnecessary `list()` call ℹ Safe fix 1 1 | x = [2, 3, 1] @@ -22,7 +21,7 @@ C413.py:3:1: C413 [*] Unnecessary `list` call around `sorted()` 5 5 | reversed(sorted(x, key=lambda e: e)) 6 6 | reversed(sorted(x, reverse=True)) -C413.py:4:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:4:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 2 | list(x) 3 | list(sorted(x)) @@ -31,7 +30,7 @@ C413.py:4:1: C413 [*] Unnecessary `reversed` call around `sorted()` 5 | reversed(sorted(x, key=lambda e: e)) 6 | reversed(sorted(x, reverse=True)) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 1 1 | x = [2, 3, 1] @@ -43,7 +42,7 @@ C413.py:4:1: C413 [*] Unnecessary `reversed` call around `sorted()` 6 6 | reversed(sorted(x, reverse=True)) 7 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) -C413.py:5:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:5:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 3 | list(sorted(x)) 4 | reversed(sorted(x)) @@ -52,7 +51,7 @@ C413.py:5:1: C413 [*] Unnecessary `reversed` call around `sorted()` 6 | reversed(sorted(x, reverse=True)) 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 2 2 | list(x) @@ -64,7 +63,7 @@ C413.py:5:1: C413 [*] Unnecessary `reversed` call around `sorted()` 7 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) 8 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) -C413.py:6:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:6:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 4 | reversed(sorted(x)) 5 | reversed(sorted(x, key=lambda e: e)) @@ -73,7 +72,7 @@ C413.py:6:1: C413 [*] Unnecessary `reversed` call around `sorted()` 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 3 3 | list(sorted(x)) @@ -85,7 +84,7 @@ C413.py:6:1: C413 [*] Unnecessary `reversed` call around `sorted()` 8 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) 9 9 | reversed(sorted(x, reverse=False)) -C413.py:7:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:7:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 5 | reversed(sorted(x, key=lambda e: e)) 6 | reversed(sorted(x, reverse=True)) @@ -94,7 +93,7 @@ C413.py:7:1: C413 [*] Unnecessary `reversed` call around `sorted()` 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) 9 | reversed(sorted(x, reverse=False)) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 4 4 | reversed(sorted(x)) @@ -106,7 +105,7 @@ C413.py:7:1: C413 [*] Unnecessary `reversed` call around `sorted()` 9 9 | reversed(sorted(x, reverse=False)) 10 10 | reversed(sorted(x, reverse=x)) -C413.py:8:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:8:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 6 | reversed(sorted(x, reverse=True)) 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) @@ -115,7 +114,7 @@ C413.py:8:1: C413 [*] Unnecessary `reversed` call around `sorted()` 9 | reversed(sorted(x, reverse=False)) 10 | reversed(sorted(x, reverse=x)) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 5 5 | reversed(sorted(x, key=lambda e: e)) @@ -127,7 +126,7 @@ C413.py:8:1: C413 [*] Unnecessary `reversed` call around `sorted()` 10 10 | reversed(sorted(x, reverse=x)) 11 11 | reversed(sorted(x, reverse=not x)) -C413.py:9:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:9:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) @@ -136,7 +135,7 @@ C413.py:9:1: C413 [*] Unnecessary `reversed` call around `sorted()` 10 | reversed(sorted(x, reverse=x)) 11 | reversed(sorted(x, reverse=not x)) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 6 6 | reversed(sorted(x, reverse=True)) @@ -148,7 +147,7 @@ C413.py:9:1: C413 [*] Unnecessary `reversed` call around `sorted()` 11 11 | reversed(sorted(x, reverse=not x)) 12 12 | -C413.py:10:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:10:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) 9 | reversed(sorted(x, reverse=False)) @@ -156,7 +155,7 @@ C413.py:10:1: C413 [*] Unnecessary `reversed` call around `sorted()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 11 | reversed(sorted(x, reverse=not x)) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 7 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) @@ -168,7 +167,7 @@ C413.py:10:1: C413 [*] Unnecessary `reversed` call around `sorted()` 12 12 | 13 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289 -C413.py:11:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:11:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 9 | reversed(sorted(x, reverse=False)) 10 | reversed(sorted(x, reverse=x)) @@ -177,7 +176,7 @@ C413.py:11:1: C413 [*] Unnecessary `reversed` call around `sorted()` 12 | 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289 | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 8 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) @@ -189,14 +188,14 @@ C413.py:11:1: C413 [*] Unnecessary `reversed` call around `sorted()` 13 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289 14 14 | reversed(sorted(i for i in range(42))) -C413.py:14:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:14:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289 14 | reversed(sorted(i for i in range(42))) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 15 | reversed(sorted((i for i in range(42)), reverse=True)) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 11 11 | reversed(sorted(x, reverse=not x)) @@ -208,7 +207,7 @@ C413.py:14:1: C413 [*] Unnecessary `reversed` call around `sorted()` 16 16 | 17 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335 -C413.py:15:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:15:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289 14 | reversed(sorted(i for i in range(42))) @@ -217,7 +216,7 @@ C413.py:15:1: C413 [*] Unnecessary `reversed` call around `sorted()` 16 | 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335 | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 12 12 | @@ -229,14 +228,14 @@ C413.py:15:1: C413 [*] Unnecessary `reversed` call around `sorted()` 17 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335 18 18 | reversed(sorted([1, 2, 3], reverse=False or True)) -C413.py:18:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:18:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335 18 | reversed(sorted([1, 2, 3], reverse=False or True)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 19 | reversed(sorted([1, 2, 3], reverse=(False or True))) | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 15 15 | reversed(sorted((i for i in range(42)), reverse=True)) @@ -246,14 +245,14 @@ C413.py:18:1: C413 [*] Unnecessary `reversed` call around `sorted()` 18 |+sorted([1, 2, 3], reverse=not (False or True)) 19 19 | reversed(sorted([1, 2, 3], reverse=(False or True))) -C413.py:19:1: C413 [*] Unnecessary `reversed` call around `sorted()` +C413.py:19:1: C413 [*] Unnecessary `reversed()` call around `sorted()` | 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335 18 | reversed(sorted([1, 2, 3], reverse=False or True)) 19 | reversed(sorted([1, 2, 3], reverse=(False or True))) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 | - = help: Remove unnecessary `reversed` call + = help: Remove unnecessary `reversed()` call ℹ Unsafe fix 16 16 | diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C414_C414.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C414_C414.py.snap index 5cfa0d7e14cc1..253374a21dbc4 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C414_C414.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C414_C414.py.snap @@ -1,8 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C414.py:2:1: C414 [*] Unnecessary `list` call within `list()` +C414.py:2:1: C414 [*] Unnecessary `list()` call within `list()` | 1 | x = [1, 2, 3] 2 | list(list(x)) @@ -10,7 +9,7 @@ C414.py:2:1: C414 [*] Unnecessary `list` call within `list()` 3 | list(tuple(x)) 4 | tuple(list(x)) | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 1 1 | x = [1, 2, 3] @@ -20,7 +19,7 @@ C414.py:2:1: C414 [*] Unnecessary `list` call within `list()` 4 4 | tuple(list(x)) 5 5 | tuple(tuple(x)) -C414.py:3:1: C414 [*] Unnecessary `tuple` call within `list()` +C414.py:3:1: C414 [*] Unnecessary `tuple()` call within `list()` | 1 | x = [1, 2, 3] 2 | list(list(x)) @@ -29,7 +28,7 @@ C414.py:3:1: C414 [*] Unnecessary `tuple` call within `list()` 4 | tuple(list(x)) 5 | tuple(tuple(x)) | - = help: Remove the inner `tuple` call + = help: Remove the inner `tuple()` call ℹ Unsafe fix 1 1 | x = [1, 2, 3] @@ -40,7 +39,7 @@ C414.py:3:1: C414 [*] Unnecessary `tuple` call within `list()` 5 5 | tuple(tuple(x)) 6 6 | set(set(x)) -C414.py:4:1: C414 [*] Unnecessary `list` call within `tuple()` +C414.py:4:1: C414 [*] Unnecessary `list()` call within `tuple()` | 2 | list(list(x)) 3 | list(tuple(x)) @@ -49,7 +48,7 @@ C414.py:4:1: C414 [*] Unnecessary `list` call within `tuple()` 5 | tuple(tuple(x)) 6 | set(set(x)) | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 1 1 | x = [1, 2, 3] @@ -61,7 +60,7 @@ C414.py:4:1: C414 [*] Unnecessary `list` call within `tuple()` 6 6 | set(set(x)) 7 7 | set(list(x)) -C414.py:5:1: C414 [*] Unnecessary `tuple` call within `tuple()` +C414.py:5:1: C414 [*] Unnecessary `tuple()` call within `tuple()` | 3 | list(tuple(x)) 4 | tuple(list(x)) @@ -70,7 +69,7 @@ C414.py:5:1: C414 [*] Unnecessary `tuple` call within `tuple()` 6 | set(set(x)) 7 | set(list(x)) | - = help: Remove the inner `tuple` call + = help: Remove the inner `tuple()` call ℹ Unsafe fix 2 2 | list(list(x)) @@ -82,7 +81,7 @@ C414.py:5:1: C414 [*] Unnecessary `tuple` call within `tuple()` 7 7 | set(list(x)) 8 8 | set(tuple(x)) -C414.py:6:1: C414 [*] Unnecessary `set` call within `set()` +C414.py:6:1: C414 [*] Unnecessary `set()` call within `set()` | 4 | tuple(list(x)) 5 | tuple(tuple(x)) @@ -91,7 +90,7 @@ C414.py:6:1: C414 [*] Unnecessary `set` call within `set()` 7 | set(list(x)) 8 | set(tuple(x)) | - = help: Remove the inner `set` call + = help: Remove the inner `set()` call ℹ Unsafe fix 3 3 | list(tuple(x)) @@ -103,7 +102,7 @@ C414.py:6:1: C414 [*] Unnecessary `set` call within `set()` 8 8 | set(tuple(x)) 9 9 | set(sorted(x)) -C414.py:7:1: C414 [*] Unnecessary `list` call within `set()` +C414.py:7:1: C414 [*] Unnecessary `list()` call within `set()` | 5 | tuple(tuple(x)) 6 | set(set(x)) @@ -112,7 +111,7 @@ C414.py:7:1: C414 [*] Unnecessary `list` call within `set()` 8 | set(tuple(x)) 9 | set(sorted(x)) | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 4 4 | tuple(list(x)) @@ -124,7 +123,7 @@ C414.py:7:1: C414 [*] Unnecessary `list` call within `set()` 9 9 | set(sorted(x)) 10 10 | set(sorted(x, key=lambda y: y)) -C414.py:8:1: C414 [*] Unnecessary `tuple` call within `set()` +C414.py:8:1: C414 [*] Unnecessary `tuple()` call within `set()` | 6 | set(set(x)) 7 | set(list(x)) @@ -133,7 +132,7 @@ C414.py:8:1: C414 [*] Unnecessary `tuple` call within `set()` 9 | set(sorted(x)) 10 | set(sorted(x, key=lambda y: y)) | - = help: Remove the inner `tuple` call + = help: Remove the inner `tuple()` call ℹ Unsafe fix 5 5 | tuple(tuple(x)) @@ -145,7 +144,7 @@ C414.py:8:1: C414 [*] Unnecessary `tuple` call within `set()` 10 10 | set(sorted(x, key=lambda y: y)) 11 11 | set(reversed(x)) -C414.py:9:1: C414 [*] Unnecessary `sorted` call within `set()` +C414.py:9:1: C414 [*] Unnecessary `sorted()` call within `set()` | 7 | set(list(x)) 8 | set(tuple(x)) @@ -154,7 +153,7 @@ C414.py:9:1: C414 [*] Unnecessary `sorted` call within `set()` 10 | set(sorted(x, key=lambda y: y)) 11 | set(reversed(x)) | - = help: Remove the inner `sorted` call + = help: Remove the inner `sorted()` call ℹ Unsafe fix 6 6 | set(set(x)) @@ -166,7 +165,7 @@ C414.py:9:1: C414 [*] Unnecessary `sorted` call within `set()` 11 11 | set(reversed(x)) 12 12 | sorted(list(x)) -C414.py:10:1: C414 [*] Unnecessary `sorted` call within `set()` +C414.py:10:1: C414 [*] Unnecessary `sorted()` call within `set()` | 8 | set(tuple(x)) 9 | set(sorted(x)) @@ -175,7 +174,7 @@ C414.py:10:1: C414 [*] Unnecessary `sorted` call within `set()` 11 | set(reversed(x)) 12 | sorted(list(x)) | - = help: Remove the inner `sorted` call + = help: Remove the inner `sorted()` call ℹ Unsafe fix 7 7 | set(list(x)) @@ -187,7 +186,7 @@ C414.py:10:1: C414 [*] Unnecessary `sorted` call within `set()` 12 12 | sorted(list(x)) 13 13 | sorted(tuple(x)) -C414.py:11:1: C414 [*] Unnecessary `reversed` call within `set()` +C414.py:11:1: C414 [*] Unnecessary `reversed()` call within `set()` | 9 | set(sorted(x)) 10 | set(sorted(x, key=lambda y: y)) @@ -196,7 +195,7 @@ C414.py:11:1: C414 [*] Unnecessary `reversed` call within `set()` 12 | sorted(list(x)) 13 | sorted(tuple(x)) | - = help: Remove the inner `reversed` call + = help: Remove the inner `reversed()` call ℹ Unsafe fix 8 8 | set(tuple(x)) @@ -208,7 +207,7 @@ C414.py:11:1: C414 [*] Unnecessary `reversed` call within `set()` 13 13 | sorted(tuple(x)) 14 14 | sorted(sorted(x)) -C414.py:12:1: C414 [*] Unnecessary `list` call within `sorted()` +C414.py:12:1: C414 [*] Unnecessary `list()` call within `sorted()` | 10 | set(sorted(x, key=lambda y: y)) 11 | set(reversed(x)) @@ -217,7 +216,7 @@ C414.py:12:1: C414 [*] Unnecessary `list` call within `sorted()` 13 | sorted(tuple(x)) 14 | sorted(sorted(x)) | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 9 9 | set(sorted(x)) @@ -229,7 +228,7 @@ C414.py:12:1: C414 [*] Unnecessary `list` call within `sorted()` 14 14 | sorted(sorted(x)) 15 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo) -C414.py:13:1: C414 [*] Unnecessary `tuple` call within `sorted()` +C414.py:13:1: C414 [*] Unnecessary `tuple()` call within `sorted()` | 11 | set(reversed(x)) 12 | sorted(list(x)) @@ -238,7 +237,7 @@ C414.py:13:1: C414 [*] Unnecessary `tuple` call within `sorted()` 14 | sorted(sorted(x)) 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo) | - = help: Remove the inner `tuple` call + = help: Remove the inner `tuple()` call ℹ Unsafe fix 10 10 | set(sorted(x, key=lambda y: y)) @@ -250,7 +249,7 @@ C414.py:13:1: C414 [*] Unnecessary `tuple` call within `sorted()` 15 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo) 16 16 | sorted(sorted(x, reverse=True), reverse=True) -C414.py:14:1: C414 [*] Unnecessary `sorted` call within `sorted()` +C414.py:14:1: C414 [*] Unnecessary `sorted()` call within `sorted()` | 12 | sorted(list(x)) 13 | sorted(tuple(x)) @@ -259,7 +258,7 @@ C414.py:14:1: C414 [*] Unnecessary `sorted` call within `sorted()` 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo) 16 | sorted(sorted(x, reverse=True), reverse=True) | - = help: Remove the inner `sorted` call + = help: Remove the inner `sorted()` call ℹ Unsafe fix 11 11 | set(reversed(x)) @@ -271,7 +270,7 @@ C414.py:14:1: C414 [*] Unnecessary `sorted` call within `sorted()` 16 16 | sorted(sorted(x, reverse=True), reverse=True) 17 17 | sorted(reversed(x)) -C414.py:15:1: C414 [*] Unnecessary `sorted` call within `sorted()` +C414.py:15:1: C414 [*] Unnecessary `sorted()` call within `sorted()` | 13 | sorted(tuple(x)) 14 | sorted(sorted(x)) @@ -280,7 +279,7 @@ C414.py:15:1: C414 [*] Unnecessary `sorted` call within `sorted()` 16 | sorted(sorted(x, reverse=True), reverse=True) 17 | sorted(reversed(x)) | - = help: Remove the inner `sorted` call + = help: Remove the inner `sorted()` call ℹ Unsafe fix 12 12 | sorted(list(x)) @@ -292,7 +291,7 @@ C414.py:15:1: C414 [*] Unnecessary `sorted` call within `sorted()` 17 17 | sorted(reversed(x)) 18 18 | sorted(list(x), key=lambda y: y) -C414.py:16:1: C414 [*] Unnecessary `sorted` call within `sorted()` +C414.py:16:1: C414 [*] Unnecessary `sorted()` call within `sorted()` | 14 | sorted(sorted(x)) 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo) @@ -301,7 +300,7 @@ C414.py:16:1: C414 [*] Unnecessary `sorted` call within `sorted()` 17 | sorted(reversed(x)) 18 | sorted(list(x), key=lambda y: y) | - = help: Remove the inner `sorted` call + = help: Remove the inner `sorted()` call ℹ Unsafe fix 13 13 | sorted(tuple(x)) @@ -313,7 +312,7 @@ C414.py:16:1: C414 [*] Unnecessary `sorted` call within `sorted()` 18 18 | sorted(list(x), key=lambda y: y) 19 19 | tuple( -C414.py:17:1: C414 [*] Unnecessary `reversed` call within `sorted()` +C414.py:17:1: C414 [*] Unnecessary `reversed()` call within `sorted()` | 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo) 16 | sorted(sorted(x, reverse=True), reverse=True) @@ -322,7 +321,7 @@ C414.py:17:1: C414 [*] Unnecessary `reversed` call within `sorted()` 18 | sorted(list(x), key=lambda y: y) 19 | tuple( | - = help: Remove the inner `reversed` call + = help: Remove the inner `reversed()` call ℹ Unsafe fix 14 14 | sorted(sorted(x)) @@ -334,7 +333,7 @@ C414.py:17:1: C414 [*] Unnecessary `reversed` call within `sorted()` 19 19 | tuple( 20 20 | list( -C414.py:18:1: C414 [*] Unnecessary `list` call within `sorted()` +C414.py:18:1: C414 [*] Unnecessary `list()` call within `sorted()` | 16 | sorted(sorted(x, reverse=True), reverse=True) 17 | sorted(reversed(x)) @@ -343,7 +342,7 @@ C414.py:18:1: C414 [*] Unnecessary `list` call within `sorted()` 19 | tuple( 20 | list( | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 15 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo) @@ -355,7 +354,7 @@ C414.py:18:1: C414 [*] Unnecessary `list` call within `sorted()` 20 20 | list( 21 21 | [x, 3, "hell"\ -C414.py:19:1: C414 [*] Unnecessary `list` call within `tuple()` +C414.py:19:1: C414 [*] Unnecessary `list()` call within `tuple()` | 17 | sorted(reversed(x)) 18 | sorted(list(x), key=lambda y: y) @@ -369,7 +368,7 @@ C414.py:19:1: C414 [*] Unnecessary `list` call within `tuple()` 25 | set(set()) 26 | set(list()) | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 17 17 | sorted(reversed(x)) @@ -384,7 +383,7 @@ C414.py:19:1: C414 [*] Unnecessary `list` call within `tuple()` 25 23 | set(set()) 26 24 | set(list()) -C414.py:25:1: C414 [*] Unnecessary `set` call within `set()` +C414.py:25:1: C414 [*] Unnecessary `set()` call within `set()` | 23 | ) 24 | ) @@ -393,7 +392,7 @@ C414.py:25:1: C414 [*] Unnecessary `set` call within `set()` 26 | set(list()) 27 | set(tuple()) | - = help: Remove the inner `set` call + = help: Remove the inner `set()` call ℹ Unsafe fix 22 22 | "o"] @@ -405,7 +404,7 @@ C414.py:25:1: C414 [*] Unnecessary `set` call within `set()` 27 27 | set(tuple()) 28 28 | sorted(reversed()) -C414.py:26:1: C414 [*] Unnecessary `list` call within `set()` +C414.py:26:1: C414 [*] Unnecessary `list()` call within `set()` | 24 | ) 25 | set(set()) @@ -414,7 +413,7 @@ C414.py:26:1: C414 [*] Unnecessary `list` call within `set()` 27 | set(tuple()) 28 | sorted(reversed()) | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 23 23 | ) @@ -426,7 +425,7 @@ C414.py:26:1: C414 [*] Unnecessary `list` call within `set()` 28 28 | sorted(reversed()) 29 29 | -C414.py:27:1: C414 [*] Unnecessary `tuple` call within `set()` +C414.py:27:1: C414 [*] Unnecessary `tuple()` call within `set()` | 25 | set(set()) 26 | set(list()) @@ -434,7 +433,7 @@ C414.py:27:1: C414 [*] Unnecessary `tuple` call within `set()` | ^^^^^^^^^^^^ C414 28 | sorted(reversed()) | - = help: Remove the inner `tuple` call + = help: Remove the inner `tuple()` call ℹ Unsafe fix 24 24 | ) @@ -446,7 +445,7 @@ C414.py:27:1: C414 [*] Unnecessary `tuple` call within `set()` 29 29 | 30 30 | # Nested sorts with differing keyword arguments. Not flagged. -C414.py:28:1: C414 [*] Unnecessary `reversed` call within `sorted()` +C414.py:28:1: C414 [*] Unnecessary `reversed()` call within `sorted()` | 26 | set(list()) 27 | set(tuple()) @@ -455,7 +454,7 @@ C414.py:28:1: C414 [*] Unnecessary `reversed` call within `sorted()` 29 | 30 | # Nested sorts with differing keyword arguments. Not flagged. | - = help: Remove the inner `reversed` call + = help: Remove the inner `reversed()` call ℹ Unsafe fix 25 25 | set(set()) @@ -467,7 +466,7 @@ C414.py:28:1: C414 [*] Unnecessary `reversed` call within `sorted()` 30 30 | # Nested sorts with differing keyword arguments. Not flagged. 31 31 | sorted(sorted(x, key=lambda y: y)) -C414.py:37:27: C414 [*] Unnecessary `list` call within `sorted()` +C414.py:37:27: C414 [*] Unnecessary `list()` call within `sorted()` | 36 | # Preserve trailing comments. 37 | xxxxxxxxxxx_xxxxx_xxxxx = sorted( @@ -481,7 +480,7 @@ C414.py:37:27: C414 [*] Unnecessary `list` call within `sorted()` 43 | 44 | xxxxxxxxxxx_xxxxx_xxxxx = sorted( | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 35 35 | @@ -493,7 +492,7 @@ C414.py:37:27: C414 [*] Unnecessary `list` call within `sorted()` 40 40 | # xx xxxx xxxxxxx xxxx xxx xxxxxxxx Nxxx 41 41 | key=lambda xxxxx: xxxxx or "", -C414.py:44:27: C414 [*] Unnecessary `list` call within `sorted()` +C414.py:44:27: C414 [*] Unnecessary `list()` call within `sorted()` | 42 | ) 43 | @@ -504,7 +503,7 @@ C414.py:44:27: C414 [*] Unnecessary `list` call within `sorted()` 47 | | ) | |_^ C414 | - = help: Remove the inner `list` call + = help: Remove the inner `list()` call ℹ Unsafe fix 42 42 | ) diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C416_C416.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C416_C416.py.snap index 47d64292d9d57..bd22b7c0e01ad 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C416_C416.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C416_C416.py.snap @@ -1,8 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C416.py:6:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`) +C416.py:6:1: C416 [*] Unnecessary list comprehension (rewrite using `list()`) | 4 | d = {"a": 1, "b": 2, "c": 3} 5 | @@ -23,7 +22,7 @@ C416.py:6:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`) 8 8 | {k: v for k, v in y} 9 9 | {k: v for k, v in d.items()} -C416.py:7:1: C416 [*] Unnecessary `set` comprehension (rewrite using `set()`) +C416.py:7:1: C416 [*] Unnecessary set comprehension (rewrite using `set()`) | 6 | [i for i in x] 7 | {i for i in x} @@ -43,7 +42,7 @@ C416.py:7:1: C416 [*] Unnecessary `set` comprehension (rewrite using `set()`) 9 9 | {k: v for k, v in d.items()} 10 10 | [(k, v) for k, v in d.items()] -C416.py:8:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`) +C416.py:8:1: C416 [*] Unnecessary dict comprehension (rewrite using `dict()`) | 6 | [i for i in x] 7 | {i for i in x} @@ -64,7 +63,7 @@ C416.py:8:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`) 10 10 | [(k, v) for k, v in d.items()] 11 11 | {k: (a, b) for k, (a, b) in d.items()} -C416.py:9:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`) +C416.py:9:1: C416 [*] Unnecessary dict comprehension (rewrite using `dict()`) | 7 | {i for i in x} 8 | {k: v for k, v in y} @@ -85,7 +84,7 @@ C416.py:9:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`) 11 11 | {k: (a, b) for k, (a, b) in d.items()} 12 12 | -C416.py:10:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`) +C416.py:10:1: C416 [*] Unnecessary list comprehension (rewrite using `list()`) | 8 | {k: v for k, v in y} 9 | {k: v for k, v in d.items()} @@ -105,7 +104,7 @@ C416.py:10:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`) 12 12 | 13 13 | [i for i, in z] -C416.py:11:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`) +C416.py:11:1: C416 [*] Unnecessary dict comprehension (rewrite using `dict()`) | 9 | {k: v for k, v in d.items()} 10 | [(k, v) for k, v in d.items()] @@ -126,7 +125,7 @@ C416.py:11:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`) 13 13 | [i for i, in z] 14 14 | [i for i, j in y] -C416.py:24:70: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`) +C416.py:24:70: C416 [*] Unnecessary list comprehension (rewrite using `list()`) | 23 | # Regression test for: https://github.com/astral-sh/ruff/issues/7196 24 | any(len(symbol_table.get_by_type(symbol_type)) > 0 for symbol_type in[t for t in SymbolType]) diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C417_C417.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C417_C417.py.snap index e952116f7305f..66f8ecc443ccd 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C417_C417.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C417_C417.py.snap @@ -1,8 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C417.py:3:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:3:1: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 1 | # Errors. 2 | nums = [1, 2, 3] @@ -11,7 +10,7 @@ C417.py:3:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express 4 | map(lambda x: str(x), nums) 5 | list(map(lambda x: x * 2, nums)) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 1 1 | # Errors. @@ -22,7 +21,7 @@ C417.py:3:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express 5 5 | list(map(lambda x: x * 2, nums)) 6 6 | set(map(lambda x: x % 2 == 0, nums)) -C417.py:4:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:4:1: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 2 | nums = [1, 2, 3] 3 | map(lambda x: x + 1, nums) @@ -31,7 +30,7 @@ C417.py:4:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express 5 | list(map(lambda x: x * 2, nums)) 6 | set(map(lambda x: x % 2 == 0, nums)) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 1 1 | # Errors. @@ -43,7 +42,7 @@ C417.py:4:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express 6 6 | set(map(lambda x: x % 2 == 0, nums)) 7 7 | dict(map(lambda v: (v, v**2), nums)) -C417.py:5:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehension) +C417.py:5:1: C417 [*] Unnecessary `map()` usage (rewrite using a list comprehension) | 3 | map(lambda x: x + 1, nums) 4 | map(lambda x: str(x), nums) @@ -52,7 +51,7 @@ C417.py:5:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehens 6 | set(map(lambda x: x % 2 == 0, nums)) 7 | dict(map(lambda v: (v, v**2), nums)) | - = help: Replace `map` with a `list` comprehension + = help: Replace `map()` with a list comprehension ℹ Unsafe fix 2 2 | nums = [1, 2, 3] @@ -64,7 +63,7 @@ C417.py:5:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehens 7 7 | dict(map(lambda v: (v, v**2), nums)) 8 8 | dict(map(lambda v: [v, v**2], nums)) -C417.py:6:1: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehension) +C417.py:6:1: C417 [*] Unnecessary `map()` usage (rewrite using a set comprehension) | 4 | map(lambda x: str(x), nums) 5 | list(map(lambda x: x * 2, nums)) @@ -73,7 +72,7 @@ C417.py:6:1: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehensi 7 | dict(map(lambda v: (v, v**2), nums)) 8 | dict(map(lambda v: [v, v**2], nums)) | - = help: Replace `map` with a `set` comprehension + = help: Replace `map()` with a set comprehension ℹ Unsafe fix 3 3 | map(lambda x: x + 1, nums) @@ -85,7 +84,7 @@ C417.py:6:1: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehensi 8 8 | dict(map(lambda v: [v, v**2], nums)) 9 9 | map(lambda: "const", nums) -C417.py:7:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehension) +C417.py:7:1: C417 [*] Unnecessary `map()` usage (rewrite using a dict comprehension) | 5 | list(map(lambda x: x * 2, nums)) 6 | set(map(lambda x: x % 2 == 0, nums)) @@ -94,7 +93,7 @@ C417.py:7:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehens 8 | dict(map(lambda v: [v, v**2], nums)) 9 | map(lambda: "const", nums) | - = help: Replace `map` with a `dict` comprehension + = help: Replace `map()` with a dict comprehension ℹ Unsafe fix 4 4 | map(lambda x: str(x), nums) @@ -106,7 +105,7 @@ C417.py:7:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehens 9 9 | map(lambda: "const", nums) 10 10 | map(lambda _: 3.0, nums) -C417.py:8:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehension) +C417.py:8:1: C417 [*] Unnecessary `map()` usage (rewrite using a dict comprehension) | 6 | set(map(lambda x: x % 2 == 0, nums)) 7 | dict(map(lambda v: (v, v**2), nums)) @@ -115,7 +114,7 @@ C417.py:8:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehens 9 | map(lambda: "const", nums) 10 | map(lambda _: 3.0, nums) | - = help: Replace `map` with a `dict` comprehension + = help: Replace `map()` with a dict comprehension ℹ Unsafe fix 5 5 | list(map(lambda x: x * 2, nums)) @@ -127,7 +126,7 @@ C417.py:8:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehens 10 10 | map(lambda _: 3.0, nums) 11 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) -C417.py:9:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:9:1: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 7 | dict(map(lambda v: (v, v**2), nums)) 8 | dict(map(lambda v: [v, v**2], nums)) @@ -136,7 +135,7 @@ C417.py:9:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express 10 | map(lambda _: 3.0, nums) 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 6 6 | set(map(lambda x: x % 2 == 0, nums)) @@ -148,7 +147,7 @@ C417.py:9:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express 11 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) 12 12 | all(map(lambda v: isinstance(v, dict), nums)) -C417.py:10:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:10:1: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 8 | dict(map(lambda v: [v, v**2], nums)) 9 | map(lambda: "const", nums) @@ -157,7 +156,7 @@ C417.py:10:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) 12 | all(map(lambda v: isinstance(v, dict), nums)) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 7 7 | dict(map(lambda v: (v, v**2), nums)) @@ -169,7 +168,7 @@ C417.py:10:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 12 12 | all(map(lambda v: isinstance(v, dict), nums)) 13 13 | filter(func, map(lambda v: v, nums)) -C417.py:11:13: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:11:13: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 9 | map(lambda: "const", nums) 10 | map(lambda _: 3.0, nums) @@ -178,7 +177,7 @@ C417.py:11:13: C417 [*] Unnecessary `map` usage (rewrite using a generator expre 12 | all(map(lambda v: isinstance(v, dict), nums)) 13 | filter(func, map(lambda v: v, nums)) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 8 8 | dict(map(lambda v: [v, v**2], nums)) @@ -190,7 +189,7 @@ C417.py:11:13: C417 [*] Unnecessary `map` usage (rewrite using a generator expre 13 13 | filter(func, map(lambda v: v, nums)) 14 14 | list(map(lambda x, y: x * y, nums)) -C417.py:12:5: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:12:5: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 10 | map(lambda _: 3.0, nums) 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) @@ -199,7 +198,7 @@ C417.py:12:5: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 13 | filter(func, map(lambda v: v, nums)) 14 | list(map(lambda x, y: x * y, nums)) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 9 9 | map(lambda: "const", nums) @@ -211,7 +210,7 @@ C417.py:12:5: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 14 14 | list(map(lambda x, y: x * y, nums)) 15 15 | -C417.py:13:14: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:13:14: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) 12 | all(map(lambda v: isinstance(v, dict), nums)) @@ -219,7 +218,7 @@ C417.py:13:14: C417 [*] Unnecessary `map` usage (rewrite using a generator expre | ^^^^^^^^^^^^^^^^^^^^^^ C417 14 | list(map(lambda x, y: x * y, nums)) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 10 10 | map(lambda _: 3.0, nums) @@ -231,7 +230,7 @@ C417.py:13:14: C417 [*] Unnecessary `map` usage (rewrite using a generator expre 15 15 | 16 16 | # When inside f-string, then the fix should be surrounded by whitespace -C417.py:14:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehension) +C417.py:14:1: C417 [*] Unnecessary `map()` usage (rewrite using a list comprehension) | 12 | all(map(lambda v: isinstance(v, dict), nums)) 13 | filter(func, map(lambda v: v, nums)) @@ -240,7 +239,7 @@ C417.py:14:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehen 15 | 16 | # When inside f-string, then the fix should be surrounded by whitespace | - = help: Replace `map` with a `list` comprehension + = help: Replace `map()` with a list comprehension ℹ Unsafe fix 11 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) @@ -252,14 +251,14 @@ C417.py:14:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehen 16 16 | # When inside f-string, then the fix should be surrounded by whitespace 17 17 | _ = f"{set(map(lambda x: x % 2 == 0, nums))}" -C417.py:17:8: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehension) +C417.py:17:8: C417 [*] Unnecessary `map()` usage (rewrite using a set comprehension) | 16 | # When inside f-string, then the fix should be surrounded by whitespace 17 | _ = f"{set(map(lambda x: x % 2 == 0, nums))}" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 18 | _ = f"{dict(map(lambda v: (v, v**2), nums))}" | - = help: Replace `map` with a `set` comprehension + = help: Replace `map()` with a set comprehension ℹ Unsafe fix 14 14 | list(map(lambda x, y: x * y, nums)) @@ -271,7 +270,7 @@ C417.py:17:8: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehens 19 19 | 20 20 | # False negatives. -C417.py:18:8: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehension) +C417.py:18:8: C417 [*] Unnecessary `map()` usage (rewrite using a dict comprehension) | 16 | # When inside f-string, then the fix should be surrounded by whitespace 17 | _ = f"{set(map(lambda x: x % 2 == 0, nums))}" @@ -280,7 +279,7 @@ C417.py:18:8: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehen 19 | 20 | # False negatives. | - = help: Replace `map` with a `dict` comprehension + = help: Replace `map()` with a dict comprehension ℹ Unsafe fix 15 15 | @@ -292,7 +291,7 @@ C417.py:18:8: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehen 20 20 | # False negatives. 21 21 | map(lambda x=2, y=1: x + y, nums, nums) -C417.py:36:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:36:1: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 35 | # Error: the `x` is overridden by the inner lambda. 36 | map(lambda x: lambda x: x, range(4)) @@ -300,7 +299,7 @@ C417.py:36:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 37 | 38 | # Ok because of the default parameters, and variadic arguments. | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 33 33 | map(lambda x: lambda: x, range(4)) @@ -312,7 +311,7 @@ C417.py:36:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 38 38 | # Ok because of the default parameters, and variadic arguments. 39 39 | map(lambda x=1: x, nums) -C417.py:47:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:47:1: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 46 | # Regression test for: https://github.com/astral-sh/ruff/issues/7121 47 | map(lambda x: x, y if y else z) @@ -320,7 +319,7 @@ C417.py:47:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 48 | map(lambda x: x, (y if y else z)) 49 | map(lambda x: x, (x, y, z)) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 44 44 | dict(map(lambda k, v: (k, v), keys, values)) @@ -331,7 +330,7 @@ C417.py:47:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 48 48 | map(lambda x: x, (y if y else z)) 49 49 | map(lambda x: x, (x, y, z)) -C417.py:48:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:48:1: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 46 | # Regression test for: https://github.com/astral-sh/ruff/issues/7121 47 | map(lambda x: x, y if y else z) @@ -339,7 +338,7 @@ C417.py:48:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 49 | map(lambda x: x, (x, y, z)) | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 45 45 | @@ -349,14 +348,14 @@ C417.py:48:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres 48 |+(x for x in (y if y else z)) 49 49 | map(lambda x: x, (x, y, z)) -C417.py:49:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) +C417.py:49:1: C417 [*] Unnecessary `map()` usage (rewrite using a generator expression) | 47 | map(lambda x: x, y if y else z) 48 | map(lambda x: x, (y if y else z)) 49 | map(lambda x: x, (x, y, z)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 | - = help: Replace `map` with a generator expression + = help: Replace `map()` with a generator expression ℹ Unsafe fix 46 46 | # Regression test for: https://github.com/astral-sh/ruff/issues/7121 diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C418_C418.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C418_C418.py.snap index d5d800e177902..4480626dc6a4e 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C418_C418.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C418_C418.py.snap @@ -1,15 +1,14 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C418.py:1:1: C418 [*] Unnecessary `dict` literal passed to `dict()` (remove the outer call to `dict()`) +C418.py:1:1: C418 [*] Unnecessary dict literal passed to `dict()` (remove the outer call to `dict()`) | 1 | dict({}) | ^^^^^^^^ C418 2 | dict({'a': 1}) 3 | dict({'x': 1 for x in range(10)}) | - = help: Remove outer `dict` call + = help: Remove outer `dict()` call ℹ Unsafe fix 1 |-dict({}) @@ -18,7 +17,7 @@ C418.py:1:1: C418 [*] Unnecessary `dict` literal passed to `dict()` (remove the 3 3 | dict({'x': 1 for x in range(10)}) 4 4 | dict( -C418.py:2:1: C418 [*] Unnecessary `dict` literal passed to `dict()` (remove the outer call to `dict()`) +C418.py:2:1: C418 [*] Unnecessary dict literal passed to `dict()` (remove the outer call to `dict()`) | 1 | dict({}) 2 | dict({'a': 1}) @@ -26,7 +25,7 @@ C418.py:2:1: C418 [*] Unnecessary `dict` literal passed to `dict()` (remove the 3 | dict({'x': 1 for x in range(10)}) 4 | dict( | - = help: Remove outer `dict` call + = help: Remove outer `dict()` call ℹ Unsafe fix 1 1 | dict({}) @@ -36,7 +35,7 @@ C418.py:2:1: C418 [*] Unnecessary `dict` literal passed to `dict()` (remove the 4 4 | dict( 5 5 | {'x': 1 for x in range(10)} -C418.py:3:1: C418 [*] Unnecessary `dict` comprehension passed to `dict()` (remove the outer call to `dict()`) +C418.py:3:1: C418 [*] Unnecessary dict comprehension passed to `dict()` (remove the outer call to `dict()`) | 1 | dict({}) 2 | dict({'a': 1}) @@ -45,7 +44,7 @@ C418.py:3:1: C418 [*] Unnecessary `dict` comprehension passed to `dict()` (remov 4 | dict( 5 | {'x': 1 for x in range(10)} | - = help: Remove outer `dict` call + = help: Remove outer `dict()` call ℹ Unsafe fix 1 1 | dict({}) @@ -56,7 +55,7 @@ C418.py:3:1: C418 [*] Unnecessary `dict` comprehension passed to `dict()` (remov 5 5 | {'x': 1 for x in range(10)} 6 6 | ) -C418.py:4:1: C418 [*] Unnecessary `dict` comprehension passed to `dict()` (remove the outer call to `dict()`) +C418.py:4:1: C418 [*] Unnecessary dict comprehension passed to `dict()` (remove the outer call to `dict()`) | 2 | dict({'a': 1}) 3 | dict({'x': 1 for x in range(10)}) @@ -67,7 +66,7 @@ C418.py:4:1: C418 [*] Unnecessary `dict` comprehension passed to `dict()` (remov 7 | 8 | dict({}, a=1) | - = help: Remove outer `dict` call + = help: Remove outer `dict()` call ℹ Unsafe fix 1 1 | dict({}) diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__preview__C409_C409.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__preview__C409_C409.py.snap index 2156bfefec5de..0b220bdcf385c 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__preview__C409_C409.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__preview__C409_C409.py.snap @@ -1,15 +1,14 @@ --- source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs -snapshot_kind: text --- -C409.py:1:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:1:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 1 | t1 = tuple([]) | ^^^^^^^^^ C409 2 | t2 = tuple([1, 2]) 3 | t3 = tuple((1, 2)) | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 1 |-t1 = tuple([]) @@ -18,7 +17,7 @@ C409.py:1:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 3 3 | t3 = tuple((1, 2)) 4 4 | t4 = tuple([ -C409.py:2:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:2:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 1 | t1 = tuple([]) 2 | t2 = tuple([1, 2]) @@ -26,7 +25,7 @@ C409.py:2:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 3 | t3 = tuple((1, 2)) 4 | t4 = tuple([ | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 1 1 | t1 = tuple([]) @@ -36,7 +35,7 @@ C409.py:2:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 4 4 | t4 = tuple([ 5 5 | 1, -C409.py:3:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) +C409.py:3:6: C409 [*] Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`) | 1 | t1 = tuple([]) 2 | t2 = tuple([1, 2]) @@ -56,7 +55,7 @@ C409.py:3:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove th 5 5 | 1, 6 6 | 2 -C409.py:4:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:4:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 2 | t2 = tuple([1, 2]) 3 | t3 = tuple((1, 2)) @@ -69,7 +68,7 @@ C409.py:4:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 8 | t5 = tuple( 9 | (1, 2) | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 1 1 | t1 = tuple([]) @@ -85,7 +84,7 @@ C409.py:4:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as 9 9 | (1, 2) 10 10 | ) -C409.py:8:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) +C409.py:8:6: C409 [*] Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`) | 6 | 2 7 | ]) @@ -111,7 +110,7 @@ C409.py:8:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove th 12 10 | tuple( # comment 13 11 | [1, 2] -C409.py:12:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:12:1: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 10 | ) 11 | @@ -122,7 +121,7 @@ C409.py:12:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 15 | 16 | tuple([ # comment | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 9 9 | (1, 2) @@ -136,7 +135,7 @@ C409.py:12:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 16 14 | tuple([ # comment 17 15 | 1, 2 -C409.py:16:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:16:1: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 14 | ) 15 | @@ -147,7 +146,7 @@ C409.py:16:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 19 | 20 | tuple(( | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 13 13 | [1, 2] @@ -162,7 +161,7 @@ C409.py:16:1: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 20 20 | tuple(( 21 21 | 1, -C409.py:20:1: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) +C409.py:20:1: C409 [*] Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`) | 18 | ]) 19 | @@ -188,7 +187,7 @@ C409.py:20:1: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove t 24 24 | t6 = tuple([1]) 25 25 | t7 = tuple((1,)) -C409.py:24:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:24:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 22 | )) 23 | @@ -197,7 +196,7 @@ C409.py:24:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 25 | t7 = tuple((1,)) 26 | t8 = tuple([1,]) | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 21 21 | 1, @@ -209,7 +208,7 @@ C409.py:24:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 26 26 | t8 = tuple([1,]) 27 27 | -C409.py:25:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) +C409.py:25:6: C409 [*] Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`) | 24 | t6 = tuple([1]) 25 | t7 = tuple((1,)) @@ -228,7 +227,7 @@ C409.py:25:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove t 27 27 | 28 28 | tuple([x for x in range(5)]) -C409.py:26:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) +C409.py:26:6: C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) | 24 | t6 = tuple([1]) 25 | t7 = tuple((1,)) @@ -237,7 +236,7 @@ C409.py:26:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite a 27 | 28 | tuple([x for x in range(5)]) | - = help: Rewrite as a `tuple` literal + = help: Rewrite as a tuple literal ℹ Unsafe fix 23 23 |