{"record":{"id":"fdc839d8adf7a0bb","repo":"astral-sh/ruff","slug":"expected-expression-listcomp-expression-setcomp","errorCode":null,"errorMessage":"Expected Expression::ListComp | Expression:SetComp | Expression:DictComp","messagePattern":"Expected Expression::ListComp \\| Expression:SetComp \\| Expression:DictComp","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs","lineNumber":654,"sourceCode":"                    rpar: vec![],\n                }))),\n                args: vec![Arg {\n                    value: inner.for_in.iter.clone(),\n                    keyword: None,\n                    equal: None,\n                    comma: None,\n                    star: \"\",\n                    whitespace_after_star: ParenthesizableWhitespace::default(),\n                    whitespace_after_arg: ParenthesizableWhitespace::default(),\n                }],\n                lpar: vec![],\n                rpar: vec![],\n                whitespace_after_func: ParenthesizableWhitespace::default(),\n                whitespace_before_args: ParenthesizableWhitespace::default(),\n            }));\n        }\n        _ => {\n            bail!(\"Expected Expression::ListComp | Expression:SetComp | Expression:DictComp\");\n        }\n    }\n\n    Ok(Edit::range_replacement(\n        pad(tree.codegen_stylist(stylist), expr.range(), locator),\n        expr.range(),\n    ))\n}\n\n/// (C417) Convert `map(lambda x: x * 2, bar)` to `(x * 2 for x in bar)`.\npub(crate) fn fix_unnecessary_map(\n    call_ast_node: &ExprCall,\n    parent: Option<&Expr>,\n    object_type: ObjectType,\n    locator: &Locator,\n    stylist: &Stylist,\n) -> Result<Edit> {\n    let module_text = locator.slice(call_ast_node);","sourceCodeStart":636,"sourceCodeEnd":672,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs#L636-L672","documentation":"Raised by the C416/unnecessary-comprehension fix, which rewrites `list(...)`, `set(...)`, and `dict(...)` calls built from redundant comprehensions. If the expression is not a list/set/dict comprehension, the fixer has no rewrite and bails with this message.","triggerScenarios":"`ruff check --fix` where the flagged expression is a comprehension-like node of an unexpected kind (e.g. a generator expression or parenthesized variant not covered by the match arms).","commonSituations":"Stale diagnostics after code edits; new AST node kinds introduced by parser changes not yet handled by the fixer; hand-crafted inputs to the fix API.","solutions":["Re-run `ruff check --fix` on the current file to refresh diagnostics.","Replace the redundant comprehension manually: `[x for x in items]` -> `list(items)`.","Ignore the fix and keep the diagnostic (`--fix-only` without this rule's fixes or a noqa)."],"exampleFix":"// before\nvalues = [x for x in items]\n// after\nvalues = list(items)","handlingStrategy":"type-guard","validationCode":"ok = isinstance(node, (ast.ListComp, ast.SetComp, ast.DictComp))","typeGuard":"def is_comprehension(expr):\n    return isinstance(expr, (ast.ListComp, ast.SetComp, ast.DictComp))","tryCatchPattern":"try:\n    apply_autofix(diagnostic)\nexcept Exception:\n    rewrite_comprehension_manually()","preventionTips":["Only expect C416 fixes on plain redundant comprehensions","Update ruff when parser AST kinds change","Suppress the fix for generator expressions"],"tags":["rust","ruff","lint-autofix","flake8-comprehensions"],"backgroundTag":"autofix-unsupported-ast-shape","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}