Skip to content

Commit c1d4378

Browse files
dylwil3ntBre
authored andcommitted
[flake8-simplify] Stabilize fix safety of multiple-with-statements (SIM117) (#20270)
Introduced in #18208. Removed gating, updated tests and docs.
1 parent 9d4692a commit c1d4378

File tree

5 files changed

+1
-363
lines changed

5 files changed

+1
-363
lines changed

crates/ruff_linter/src/preview.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,6 @@ pub(crate) const fn is_allow_nested_roots_enabled(settings: &LinterSettings) ->
200200
settings.preview.is_enabled()
201201
}
202202

203-
// https://github.com/astral-sh/ruff/pull/18208
204-
pub(crate) const fn is_multiple_with_statements_fix_safe_enabled(
205-
settings: &LinterSettings,
206-
) -> bool {
207-
settings.preview.is_enabled()
208-
}
209-
210203
// https://github.com/astral-sh/ruff/pull/18400
211204
pub(crate) const fn is_ignore_init_files_in_useless_alias_enabled(
212205
settings: &LinterSettings,

crates/ruff_linter/src/rules/flake8_simplify/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ mod tests {
5959
Ok(())
6060
}
6161

62-
#[test_case(Rule::MultipleWithStatements, Path::new("SIM117.py"))]
6362
#[test_case(Rule::SplitStaticString, Path::new("SIM905.py"))]
6463
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
6564
let snapshot = format!(

crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use super::fix_with;
1010
use crate::Fix;
1111
use crate::checkers::ast::Checker;
1212
use crate::fix::edits::fits;
13-
use crate::preview::is_multiple_with_statements_fix_safe_enabled;
1413
use crate::{FixAvailability, Violation};
1514

1615
/// ## What it does
@@ -45,15 +44,8 @@ use crate::{FixAvailability, Violation};
4544
/// pass
4645
/// ```
4746
///
48-
/// ## Fix safety
49-
///
50-
/// This fix is marked as always unsafe unless [preview] mode is enabled, in which case it is always
51-
/// marked as safe. Note that the fix is unavailable if it would remove comments (in either case).
52-
///
5347
/// ## References
5448
/// - [Python documentation: The `with` statement](https://docs.python.org/3/reference/compound_stmts.html#the-with-statement)
55-
///
56-
/// [preview]: https://docs.astral.sh/ruff/preview/
5749
#[derive(ViolationMetadata)]
5850
pub(crate) struct MultipleWithStatements;
5951

@@ -195,11 +187,7 @@ pub(crate) fn multiple_with_statements(
195187
checker.settings().tab_size,
196188
)
197189
}) {
198-
if is_multiple_with_statements_fix_safe_enabled(checker.settings()) {
199-
Ok(Some(Fix::safe_edit(edit)))
200-
} else {
201-
Ok(Some(Fix::unsafe_edit(edit)))
202-
}
190+
Ok(Some(Fix::safe_edit(edit)))
203191
} else {
204192
Ok(None)
205193
}

crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM117_SIM117.py.snap

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ help: Combine `with` statements
2020
4 |
2121
5 | # SIM117
2222
6 | with A():
23-
note: This is an unsafe fix and may change runtime behavior
2423

2524
SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
2625
--> SIM117.py:7:1
@@ -46,7 +45,6 @@ help: Combine `with` statements
4645
10 |
4746
11 | # SIM117
4847
12 | with A() as a:
49-
note: This is an unsafe fix and may change runtime behavior
5048

5149
SIM117 Use a single `with` statement with multiple contexts instead of nested `with` statements
5250
--> SIM117.py:13:1
@@ -84,7 +82,6 @@ help: Combine `with` statements
8482
22 |
8583
23 | # OK
8684
24 | with A() as a:
87-
note: This is an unsafe fix and may change runtime behavior
8885

8986
SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
9087
--> SIM117.py:47:1
@@ -107,7 +104,6 @@ help: Combine `with` statements
107104
49 |
108105
50 | while True:
109106
51 | # SIM117
110-
note: This is an unsafe fix and may change runtime behavior
111107

112108
SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
113109
--> SIM117.py:53:5
@@ -144,7 +140,6 @@ help: Combine `with` statements
144140
64 | "this for some reason")
145141
65 |
146142
66 | # SIM117
147-
note: This is an unsafe fix and may change runtime behavior
148143

149144
SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
150145
--> SIM117.py:68:1
@@ -171,7 +166,6 @@ help: Combine `with` statements
171166
73 |
172167
74 | # SIM117
173168
75 | with A() as a:
174-
note: This is an unsafe fix and may change runtime behavior
175169

176170
SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
177171
--> SIM117.py:76:1
@@ -203,7 +197,6 @@ help: Combine `with` statements
203197
81 |
204198
82 | # SIM117
205199
83 | with (
206-
note: This is an unsafe fix and may change runtime behavior
207200

208201
SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
209202
--> SIM117.py:84:1
@@ -237,7 +230,6 @@ help: Combine `with` statements
237230
90 |
238231
91 | # SIM117 (auto-fixable)
239232
92 | with A("01ß9💣2ℝ8901ß9💣2ℝ8901ß9💣2ℝ89") as a:
240-
note: This is an unsafe fix and may change runtime behavior
241233

242234
SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
243235
--> SIM117.py:95:1
@@ -260,7 +252,6 @@ help: Combine `with` statements
260252
97 |
261253
98 | # SIM117 (not auto-fixable too long)
262254
99 | with A("01ß9💣2ℝ8901ß9💣2ℝ8901ß9💣2ℝ890") as a:
263-
note: This is an unsafe fix and may change runtime behavior
264255

265256
SIM117 Use a single `with` statement with multiple contexts instead of nested `with` statements
266257
--> SIM117.py:100:1
@@ -319,7 +310,6 @@ help: Combine `with` statements
319310
136 |
320311
137 | # Allow cascading for some statements.
321312
138 | import anyio
322-
note: This is an unsafe fix and may change runtime behavior
323313

324314
SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
325315
--> SIM117.py:163:1
@@ -339,4 +329,3 @@ help: Combine `with` statements
339329
- pass
340330
163 + async with asyncio.timeout(1), A(), B():
341331
164 + pass
342-
note: This is an unsafe fix and may change runtime behavior

0 commit comments

Comments
 (0)