Skip to content

Commit

Permalink
Remove preview gating for flake8-simplify rules (#9686)
Browse files Browse the repository at this point in the history
## Summary

Un-gates detecting `dict.get` rewrites in `if` expressions (rather than
just `if` statements).
  • Loading branch information
charliermarsh committed Jan 29, 2024
1 parent d90a420 commit 97afc70
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 207 deletions.
1 change: 0 additions & 1 deletion crates/ruff_linter/src/rules/flake8_simplify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ mod tests {
}

#[test_case(Rule::YodaConditions, Path::new("SIM300.py"))]
#[test_case(Rule::IfElseBlockInsteadOfDictGet, Path::new("SIM401.py"))]
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!(
"preview__{}_{}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@ pub(crate) fn if_exp_instead_of_dict_get(
body: &Expr,
orelse: &Expr,
) {
if checker.settings.preview.is_disabled() {
return;
}

let Expr::Compare(ast::ExprCompare {
left: test_key,
ops,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,44 @@ SIM401.py:45:5: SIM401 [*] Use `vars[idx] = a_dict.get(key, "default")` instead
50 47 | ###
51 48 | # Negative cases

SIM401.py:123:7: SIM401 [*] Use `a_dict.get(key, "default3")` instead of an `if` block
|
122 | # SIM401
123 | var = a_dict[key] if key in a_dict else "default3"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM401
124 |
125 | # SIM401
|
= help: Replace with `a_dict.get(key, "default3")`

Unsafe fix
120 120 | ###
121 121 |
122 122 | # SIM401
123 |-var = a_dict[key] if key in a_dict else "default3"
123 |+var = a_dict.get(key, "default3")
124 124 |
125 125 | # SIM401
126 126 | var = "default-1" if key not in a_dict else a_dict[key]

SIM401.py:126:7: SIM401 [*] Use `a_dict.get(key, "default-1")` instead of an `if` block
|
125 | # SIM401
126 | var = "default-1" if key not in a_dict else a_dict[key]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM401
127 |
128 | # OK (default contains effect)
|
= help: Replace with `a_dict.get(key, "default-1")`

Unsafe fix
123 123 | var = a_dict[key] if key in a_dict else "default3"
124 124 |
125 125 | # SIM401
126 |-var = "default-1" if key not in a_dict else a_dict[key]
126 |+var = a_dict.get(key, "default-1")
127 127 |
128 128 | # OK (default contains effect)
129 129 | var = a_dict[key] if key in a_dict else val1 + val2


This file was deleted.

0 comments on commit 97afc70

Please sign in to comment.