Skip to content

Commit abf685b

Browse files
authored
[flake8-bugbear] Omit annotation in preview fix for B006 (#20877)
Closes #20864
1 parent e1e3eb7 commit abf685b

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,10 @@ fn move_initialization(
188188
content.push_str(stylist.line_ending().as_str());
189189
content.push_str(stylist.indentation());
190190
if is_b006_unsafe_fix_preserve_assignment_expr_enabled(checker.settings()) {
191-
let annotation = if let Some(ann) = parameter.annotation() {
192-
format!(": {}", locator.slice(ann))
193-
} else {
194-
String::new()
195-
};
196191
let _ = write!(
197192
&mut content,
198-
"{}{} = {}",
193+
"{} = {}",
199194
parameter.parameter.name(),
200-
annotation,
201195
locator.slice(
202196
parenthesized_range(
203197
default.into(),

crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_5.py.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ help: Replace with `None`; initialize within function
1616
5 + def import_module_wrong(value: dict[str, str] = None):
1717
6 | import os
1818
7 + if value is None:
19-
8 + value: dict[str, str] = {}
19+
8 + value = {}
2020
9 |
2121
10 |
2222
11 | def import_module_with_values_wrong(value: dict[str, str] = {}):
@@ -38,7 +38,7 @@ help: Replace with `None`; initialize within function
3838
10 | import os
3939
11 |
4040
12 + if value is None:
41-
13 + value: dict[str, str] = {}
41+
13 + value = {}
4242
14 | return 2
4343
15 |
4444
16 |
@@ -62,7 +62,7 @@ help: Replace with `None`; initialize within function
6262
17 | import sys
6363
18 | import itertools
6464
19 + if value is None:
65-
20 + value: dict[str, str] = {}
65+
20 + value = {}
6666
21 |
6767
22 |
6868
23 | def from_import_module_wrong(value: dict[str, str] = {}):
@@ -83,7 +83,7 @@ help: Replace with `None`; initialize within function
8383
21 + def from_import_module_wrong(value: dict[str, str] = None):
8484
22 | from os import path
8585
23 + if value is None:
86-
24 + value: dict[str, str] = {}
86+
24 + value = {}
8787
25 |
8888
26 |
8989
27 | def from_imports_module_wrong(value: dict[str, str] = {}):
@@ -106,7 +106,7 @@ help: Replace with `None`; initialize within function
106106
26 | from os import path
107107
27 | from sys import version_info
108108
28 + if value is None:
109-
29 + value: dict[str, str] = {}
109+
29 + value = {}
110110
30 |
111111
31 |
112112
32 | def import_and_from_imports_module_wrong(value: dict[str, str] = {}):
@@ -129,7 +129,7 @@ help: Replace with `None`; initialize within function
129129
31 | import os
130130
32 | from sys import version_info
131131
33 + if value is None:
132-
34 + value: dict[str, str] = {}
132+
34 + value = {}
133133
35 |
134134
36 |
135135
37 | def import_docstring_module_wrong(value: dict[str, str] = {}):
@@ -152,7 +152,7 @@ help: Replace with `None`; initialize within function
152152
36 | """Docstring"""
153153
37 | import os
154154
38 + if value is None:
155-
39 + value: dict[str, str] = {}
155+
39 + value = {}
156156
40 |
157157
41 |
158158
42 | def import_module_wrong(value: dict[str, str] = {}):
@@ -175,7 +175,7 @@ help: Replace with `None`; initialize within function
175175
41 | """Docstring"""
176176
42 | import os; import sys
177177
43 + if value is None:
178-
44 + value: dict[str, str] = {}
178+
44 + value = {}
179179
45 |
180180
46 |
181181
47 | def import_module_wrong(value: dict[str, str] = {}):
@@ -197,7 +197,7 @@ help: Replace with `None`; initialize within function
197197
45 + def import_module_wrong(value: dict[str, str] = None):
198198
46 | """Docstring"""
199199
47 + if value is None:
200-
48 + value: dict[str, str] = {}
200+
48 + value = {}
201201
49 | import os; import sys; x = 1
202202
50 |
203203
51 |
@@ -220,7 +220,7 @@ help: Replace with `None`; initialize within function
220220
51 | """Docstring"""
221221
52 | import os; import sys
222222
53 + if value is None:
223-
54 + value: dict[str, str] = {}
223+
54 + value = {}
224224
55 |
225225
56 |
226226
57 | def import_module_wrong(value: dict[str, str] = {}):
@@ -241,7 +241,7 @@ help: Replace with `None`; initialize within function
241241
55 + def import_module_wrong(value: dict[str, str] = None):
242242
56 | import os; import sys
243243
57 + if value is None:
244-
58 + value: dict[str, str] = {}
244+
58 + value = {}
245245
59 |
246246
60 |
247247
61 | def import_module_wrong(value: dict[str, str] = {}):
@@ -261,7 +261,7 @@ help: Replace with `None`; initialize within function
261261
- def import_module_wrong(value: dict[str, str] = {}):
262262
59 + def import_module_wrong(value: dict[str, str] = None):
263263
60 + if value is None:
264-
61 + value: dict[str, str] = {}
264+
61 + value = {}
265265
62 | import os; import sys; x = 1
266266
63 |
267267
64 |
@@ -282,7 +282,7 @@ help: Replace with `None`; initialize within function
282282
63 + def import_module_wrong(value: dict[str, str] = None):
283283
64 | import os; import sys
284284
65 + if value is None:
285-
66 + value: dict[str, str] = {}
285+
66 + value = {}
286286
67 |
287287
68 |
288288
69 | def import_module_wrong(value: dict[str, str] = {}): import os

crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__preview__B006_B006_8.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ help: Replace with `None`; initialize within function
5151
10 + def baz(a: list = None):
5252
11 | """This one raises a different exception"""
5353
12 + if a is None:
54-
13 + a: list = []
54+
13 + a = []
5555
14 | raise IndexError()
5656
15 |
5757
16 |

0 commit comments

Comments
 (0)