Upgrade mutable-argument-defaults to unsafe (#8108)

This commit is contained in:
Claudio Jolowicz 2023-10-21 21:29:46 +02:00 committed by GitHub
parent e0f9dbcd10
commit 2414f23abb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 93 additions and 87 deletions

View file

@ -30,6 +30,12 @@ use crate::checkers::ast::Checker;
/// Types outside of the standard library can be marked as immutable with the
/// [`flake8-bugbear.extend-immutable-calls`] configuration option.
///
/// ## Known problems
/// Mutable argument defaults can be used intentionally to cache computation
/// results. Replacing the default with `None` or an immutable data structure
/// does not work for such usages. Instead, prefer the `@functools.lru_cache`
/// decorator from the standard library.
///
/// ## Example
/// ```python
/// def add_to_list(item, some_list=[]):
@ -197,5 +203,5 @@ fn move_initialization(
}
let initialization_edit = Edit::insertion(content, pos);
Some(Fix::display_edits(default_edit, [initialization_edit]))
Some(Fix::unsafe_edits(default_edit, [initialization_edit]))
}

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_1.py:3:22: B006 Do not use mutable data structures for argument defaults
B006_1.py:3:22: B006 [*] Do not use mutable data structures for argument defaults
|
1 | # Docstring followed by a newline
2 |
@ -12,7 +12,7 @@ B006_1.py:3:22: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
1 1 | # Docstring followed by a newline
2 2 |
3 |-def foobar(foor, bar={}):

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_2.py:4:22: B006 Do not use mutable data structures for argument defaults
B006_2.py:4:22: B006 [*] Do not use mutable data structures for argument defaults
|
2 | # Regression test for https://github.com/astral-sh/ruff/issues/7155
3 |
@ -12,7 +12,7 @@ B006_2.py:4:22: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
1 1 | # Docstring followed by whitespace with no newline
2 2 | # Regression test for https://github.com/astral-sh/ruff/issues/7155
3 3 |

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_3.py:4:22: B006 Do not use mutable data structures for argument defaults
B006_3.py:4:22: B006 [*] Do not use mutable data structures for argument defaults
|
4 | def foobar(foor, bar={}):
| ^^ B006
@ -10,7 +10,7 @@ B006_3.py:4:22: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
1 1 | # Docstring with no newline
2 2 |
3 3 |

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_4.py:7:26: B006 Do not use mutable data structures for argument defaults
B006_4.py:7:26: B006 [*] Do not use mutable data structures for argument defaults
|
6 | class FormFeedIndent:
7 | def __init__(self, a=[]):
@ -10,7 +10,7 @@ B006_4.py:7:26: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
4 4 |
5 5 |
6 6 | class FormFeedIndent:

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_5.py:5:49: B006 Do not use mutable data structures for argument defaults
B006_5.py:5:49: B006 [*] Do not use mutable data structures for argument defaults
|
5 | def import_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -9,7 +9,7 @@ B006_5.py:5:49: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
2 2 | # https://github.com/astral-sh/ruff/issues/7616
3 3 |
4 4 |
@ -22,7 +22,7 @@ B006_5.py:5:49: B006 Do not use mutable data structures for argument defaults
8 10 |
9 11 | def import_module_with_values_wrong(value: dict[str, str] = {}):
B006_5.py:9:61: B006 Do not use mutable data structures for argument defaults
B006_5.py:9:61: B006 [*] Do not use mutable data structures for argument defaults
|
9 | def import_module_with_values_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -30,7 +30,7 @@ B006_5.py:9:61: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
6 6 | import os
7 7 |
8 8 |
@ -44,7 +44,7 @@ B006_5.py:9:61: B006 Do not use mutable data structures for argument defaults
13 15 |
14 16 |
B006_5.py:15:50: B006 Do not use mutable data structures for argument defaults
B006_5.py:15:50: B006 [*] Do not use mutable data structures for argument defaults
|
15 | def import_modules_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -53,7 +53,7 @@ B006_5.py:15:50: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
12 12 | return 2
13 13 |
14 14 |
@ -68,7 +68,7 @@ B006_5.py:15:50: B006 Do not use mutable data structures for argument defaults
20 22 |
21 23 | def from_import_module_wrong(value: dict[str, str] = {}):
B006_5.py:21:54: B006 Do not use mutable data structures for argument defaults
B006_5.py:21:54: B006 [*] Do not use mutable data structures for argument defaults
|
21 | def from_import_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -76,7 +76,7 @@ B006_5.py:21:54: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
18 18 | import itertools
19 19 |
20 20 |
@ -89,7 +89,7 @@ B006_5.py:21:54: B006 Do not use mutable data structures for argument defaults
24 26 |
25 27 | def from_imports_module_wrong(value: dict[str, str] = {}):
B006_5.py:25:55: B006 Do not use mutable data structures for argument defaults
B006_5.py:25:55: B006 [*] Do not use mutable data structures for argument defaults
|
25 | def from_imports_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -98,7 +98,7 @@ B006_5.py:25:55: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
22 22 | from os import path
23 23 |
24 24 |
@ -112,7 +112,7 @@ B006_5.py:25:55: B006 Do not use mutable data structures for argument defaults
29 31 |
30 32 | def import_and_from_imports_module_wrong(value: dict[str, str] = {}):
B006_5.py:30:66: B006 Do not use mutable data structures for argument defaults
B006_5.py:30:66: B006 [*] Do not use mutable data structures for argument defaults
|
30 | def import_and_from_imports_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -121,7 +121,7 @@ B006_5.py:30:66: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
27 27 | from sys import version_info
28 28 |
29 29 |
@ -135,7 +135,7 @@ B006_5.py:30:66: B006 Do not use mutable data structures for argument defaults
34 36 |
35 37 | def import_docstring_module_wrong(value: dict[str, str] = {}):
B006_5.py:35:59: B006 Do not use mutable data structures for argument defaults
B006_5.py:35:59: B006 [*] Do not use mutable data structures for argument defaults
|
35 | def import_docstring_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -144,7 +144,7 @@ B006_5.py:35:59: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
32 32 | from sys import version_info
33 33 |
34 34 |
@ -158,7 +158,7 @@ B006_5.py:35:59: B006 Do not use mutable data structures for argument defaults
39 41 |
40 42 | def import_module_wrong(value: dict[str, str] = {}):
B006_5.py:40:49: B006 Do not use mutable data structures for argument defaults
B006_5.py:40:49: B006 [*] Do not use mutable data structures for argument defaults
|
40 | def import_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -167,7 +167,7 @@ B006_5.py:40:49: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
37 37 | import os
38 38 |
39 39 |
@ -181,7 +181,7 @@ B006_5.py:40:49: B006 Do not use mutable data structures for argument defaults
44 46 |
45 47 | def import_module_wrong(value: dict[str, str] = {}):
B006_5.py:45:49: B006 Do not use mutable data structures for argument defaults
B006_5.py:45:49: B006 [*] Do not use mutable data structures for argument defaults
|
45 | def import_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -190,7 +190,7 @@ B006_5.py:45:49: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
42 42 | import os; import sys
43 43 |
44 44 |
@ -203,7 +203,7 @@ B006_5.py:45:49: B006 Do not use mutable data structures for argument defaults
48 50 |
49 51 |
B006_5.py:50:49: B006 Do not use mutable data structures for argument defaults
B006_5.py:50:49: B006 [*] Do not use mutable data structures for argument defaults
|
50 | def import_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -212,7 +212,7 @@ B006_5.py:50:49: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
47 47 | import os; import sys; x = 1
48 48 |
49 49 |
@ -226,7 +226,7 @@ B006_5.py:50:49: B006 Do not use mutable data structures for argument defaults
54 56 |
55 57 | def import_module_wrong(value: dict[str, str] = {}):
B006_5.py:55:49: B006 Do not use mutable data structures for argument defaults
B006_5.py:55:49: B006 [*] Do not use mutable data structures for argument defaults
|
55 | def import_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -234,7 +234,7 @@ B006_5.py:55:49: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
52 52 | import os; import sys
53 53 |
54 54 |
@ -247,7 +247,7 @@ B006_5.py:55:49: B006 Do not use mutable data structures for argument defaults
58 60 |
59 61 | def import_module_wrong(value: dict[str, str] = {}):
B006_5.py:59:49: B006 Do not use mutable data structures for argument defaults
B006_5.py:59:49: B006 [*] Do not use mutable data structures for argument defaults
|
59 | def import_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -255,7 +255,7 @@ B006_5.py:59:49: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
56 56 | import os; import sys
57 57 |
58 58 |
@ -267,7 +267,7 @@ B006_5.py:59:49: B006 Do not use mutable data structures for argument defaults
61 63 |
62 64 |
B006_5.py:63:49: B006 Do not use mutable data structures for argument defaults
B006_5.py:63:49: B006 [*] Do not use mutable data structures for argument defaults
|
63 | def import_module_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -275,7 +275,7 @@ B006_5.py:63:49: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
60 60 | import os; import sys; x = 1
61 61 |
62 62 |

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_6.py:4:22: B006 Do not use mutable data structures for argument defaults
B006_6.py:4:22: B006 [*] Do not use mutable data structures for argument defaults
|
2 | # Same as B006_2.py, but import instead of docstring
3 |
@ -11,7 +11,7 @@ B006_6.py:4:22: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
1 1 | # Import followed by whitespace with no newline
2 2 | # Same as B006_2.py, but import instead of docstring
3 3 |

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_7.py:4:22: B006 Do not use mutable data structures for argument defaults
B006_7.py:4:22: B006 [*] Do not use mutable data structures for argument defaults
|
2 | # Same as B006_3.py, but import instead of docstring
3 |
@ -11,7 +11,7 @@ B006_7.py:4:22: B006 Do not use mutable data structures for argument defaults
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
1 1 | # Import with no newline
2 2 | # Same as B006_3.py, but import instead of docstring
3 3 |

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_B008.py:63:25: B006 Do not use mutable data structures for argument defaults
B006_B008.py:63:25: B006 [*] Do not use mutable data structures for argument defaults
|
63 | def this_is_wrong(value=[1, 2, 3]):
| ^^^^^^^^^ B006
@ -9,7 +9,7 @@ B006_B008.py:63:25: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
60 60 | # Flag mutable literals/comprehensions
61 61 |
62 62 |
@ -21,7 +21,7 @@ B006_B008.py:63:25: B006 Do not use mutable data structures for argument default
65 67 |
66 68 |
B006_B008.py:67:30: B006 Do not use mutable data structures for argument defaults
B006_B008.py:67:30: B006 [*] Do not use mutable data structures for argument defaults
|
67 | def this_is_also_wrong(value={}):
| ^^ B006
@ -29,7 +29,7 @@ B006_B008.py:67:30: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
64 64 | ...
65 65 |
66 66 |
@ -41,7 +41,7 @@ B006_B008.py:67:30: B006 Do not use mutable data structures for argument default
69 71 |
70 72 |
B006_B008.py:73:52: B006 Do not use mutable data structures for argument defaults
B006_B008.py:73:52: B006 [*] Do not use mutable data structures for argument defaults
|
71 | class Foo:
72 | @staticmethod
@ -51,7 +51,7 @@ B006_B008.py:73:52: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
70 70 |
71 71 | class Foo:
72 72 | @staticmethod
@ -63,7 +63,7 @@ B006_B008.py:73:52: B006 Do not use mutable data structures for argument default
75 77 |
76 78 |
B006_B008.py:77:31: B006 Do not use mutable data structures for argument defaults
B006_B008.py:77:31: B006 [*] Do not use mutable data structures for argument defaults
|
77 | def multiline_arg_wrong(value={
| _______________________________^
@ -74,7 +74,7 @@ B006_B008.py:77:31: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
74 74 | pass
75 75 |
76 76 |
@ -97,7 +97,7 @@ B006_B008.py:82:36: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
B006_B008.py:85:20: B006 Do not use mutable data structures for argument defaults
B006_B008.py:85:20: B006 [*] Do not use mutable data structures for argument defaults
|
85 | def and_this(value=set()):
| ^^^^^ B006
@ -105,7 +105,7 @@ B006_B008.py:85:20: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
82 82 | def single_line_func_wrong(value = {}): ...
83 83 |
84 84 |
@ -117,7 +117,7 @@ B006_B008.py:85:20: B006 Do not use mutable data structures for argument default
87 89 |
88 90 |
B006_B008.py:89:20: B006 Do not use mutable data structures for argument defaults
B006_B008.py:89:20: B006 [*] Do not use mutable data structures for argument defaults
|
89 | def this_too(value=collections.OrderedDict()):
| ^^^^^^^^^^^^^^^^^^^^^^^^^ B006
@ -125,7 +125,7 @@ B006_B008.py:89:20: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
86 86 | ...
87 87 |
88 88 |
@ -137,7 +137,7 @@ B006_B008.py:89:20: B006 Do not use mutable data structures for argument default
91 93 |
92 94 |
B006_B008.py:93:32: B006 Do not use mutable data structures for argument defaults
B006_B008.py:93:32: B006 [*] Do not use mutable data structures for argument defaults
|
93 | async def async_this_too(value=collections.defaultdict()):
| ^^^^^^^^^^^^^^^^^^^^^^^^^ B006
@ -145,7 +145,7 @@ B006_B008.py:93:32: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
90 90 | ...
91 91 |
92 92 |
@ -157,7 +157,7 @@ B006_B008.py:93:32: B006 Do not use mutable data structures for argument default
95 97 |
96 98 |
B006_B008.py:97:26: B006 Do not use mutable data structures for argument defaults
B006_B008.py:97:26: B006 [*] Do not use mutable data structures for argument defaults
|
97 | def dont_forget_me(value=collections.deque()):
| ^^^^^^^^^^^^^^^^^^^ B006
@ -165,7 +165,7 @@ B006_B008.py:97:26: B006 Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
94 94 | ...
95 95 |
96 96 |
@ -177,7 +177,7 @@ B006_B008.py:97:26: B006 Do not use mutable data structures for argument default
99 101 |
100 102 |
B006_B008.py:102:46: B006 Do not use mutable data structures for argument defaults
B006_B008.py:102:46: B006 [*] Do not use mutable data structures for argument defaults
|
101 | # N.B. we're also flagging the function call in the comprehension
102 | def list_comprehension_also_not_okay(default=[i**2 for i in range(3)]):
@ -186,7 +186,7 @@ B006_B008.py:102:46: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
99 99 |
100 100 |
101 101 | # N.B. we're also flagging the function call in the comprehension
@ -198,7 +198,7 @@ B006_B008.py:102:46: B006 Do not use mutable data structures for argument defaul
104 106 |
105 107 |
B006_B008.py:106:46: B006 Do not use mutable data structures for argument defaults
B006_B008.py:106:46: B006 [*] Do not use mutable data structures for argument defaults
|
106 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}):
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B006
@ -206,7 +206,7 @@ B006_B008.py:106:46: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
103 103 | pass
104 104 |
105 105 |
@ -218,7 +218,7 @@ B006_B008.py:106:46: B006 Do not use mutable data structures for argument defaul
108 110 |
109 111 |
B006_B008.py:110:45: B006 Do not use mutable data structures for argument defaults
B006_B008.py:110:45: B006 [*] Do not use mutable data structures for argument defaults
|
110 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
| ^^^^^^^^^^^^^^^^^^^^^^^^ B006
@ -226,7 +226,7 @@ B006_B008.py:110:45: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
107 107 | pass
108 108 |
109 109 |
@ -238,7 +238,7 @@ B006_B008.py:110:45: B006 Do not use mutable data structures for argument defaul
112 114 |
113 115 |
B006_B008.py:114:33: B006 Do not use mutable data structures for argument defaults
B006_B008.py:114:33: B006 [*] Do not use mutable data structures for argument defaults
|
114 | def kwonlyargs_mutable(*, value=[]):
| ^^ B006
@ -246,7 +246,7 @@ B006_B008.py:114:33: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
111 111 | pass
112 112 |
113 113 |
@ -258,7 +258,7 @@ B006_B008.py:114:33: B006 Do not use mutable data structures for argument defaul
116 118 |
117 119 |
B006_B008.py:239:20: B006 Do not use mutable data structures for argument defaults
B006_B008.py:239:20: B006 [*] Do not use mutable data structures for argument defaults
|
237 | # B006 and B008
238 | # We should handle arbitrary nesting of these B008.
@ -268,7 +268,7 @@ B006_B008.py:239:20: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
236 236 |
237 237 | # B006 and B008
238 238 | # We should handle arbitrary nesting of these B008.
@ -280,7 +280,7 @@ B006_B008.py:239:20: B006 Do not use mutable data structures for argument defaul
241 243 |
242 244 |
B006_B008.py:276:27: B006 Do not use mutable data structures for argument defaults
B006_B008.py:276:27: B006 [*] Do not use mutable data structures for argument defaults
|
275 | def mutable_annotations(
276 | a: list[int] | None = [],
@ -290,7 +290,7 @@ B006_B008.py:276:27: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
273 273 |
274 274 |
275 275 | def mutable_annotations(
@ -306,7 +306,7 @@ B006_B008.py:276:27: B006 Do not use mutable data structures for argument defaul
282 284 |
283 285 |
B006_B008.py:277:35: B006 Do not use mutable data structures for argument defaults
B006_B008.py:277:35: B006 [*] Do not use mutable data structures for argument defaults
|
275 | def mutable_annotations(
276 | a: list[int] | None = [],
@ -317,7 +317,7 @@ B006_B008.py:277:35: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
274 274 |
275 275 | def mutable_annotations(
276 276 | a: list[int] | None = [],
@ -332,7 +332,7 @@ B006_B008.py:277:35: B006 Do not use mutable data structures for argument defaul
282 284 |
283 285 |
B006_B008.py:278:62: B006 Do not use mutable data structures for argument defaults
B006_B008.py:278:62: B006 [*] Do not use mutable data structures for argument defaults
|
276 | a: list[int] | None = [],
277 | b: Optional[Dict[int, int]] = {},
@ -343,7 +343,7 @@ B006_B008.py:278:62: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
275 275 | def mutable_annotations(
276 276 | a: list[int] | None = [],
277 277 | b: Optional[Dict[int, int]] = {},
@ -357,7 +357,7 @@ B006_B008.py:278:62: B006 Do not use mutable data structures for argument defaul
282 284 |
283 285 |
B006_B008.py:279:80: B006 Do not use mutable data structures for argument defaults
B006_B008.py:279:80: B006 [*] Do not use mutable data structures for argument defaults
|
277 | b: Optional[Dict[int, int]] = {},
278 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
@ -368,7 +368,7 @@ B006_B008.py:279:80: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
276 276 | a: list[int] | None = [],
277 277 | b: Optional[Dict[int, int]] = {},
278 278 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
@ -381,7 +381,7 @@ B006_B008.py:279:80: B006 Do not use mutable data structures for argument defaul
282 284 |
283 285 |
B006_B008.py:284:52: B006 Do not use mutable data structures for argument defaults
B006_B008.py:284:52: B006 [*] Do not use mutable data structures for argument defaults
|
284 | def single_line_func_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -389,7 +389,7 @@ B006_B008.py:284:52: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
281 281 | pass
282 282 |
283 283 |
@ -402,7 +402,7 @@ B006_B008.py:284:52: B006 Do not use mutable data structures for argument defaul
287 289 |
288 290 | def single_line_func_wrong(value: dict[str, str] = {}):
B006_B008.py:288:52: B006 Do not use mutable data structures for argument defaults
B006_B008.py:288:52: B006 [*] Do not use mutable data structures for argument defaults
|
288 | def single_line_func_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -411,7 +411,7 @@ B006_B008.py:288:52: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
285 285 | """Docstring"""
286 286 |
287 287 |
@ -424,7 +424,7 @@ B006_B008.py:288:52: B006 Do not use mutable data structures for argument defaul
291 293 |
292 294 |
B006_B008.py:293:52: B006 Do not use mutable data structures for argument defaults
B006_B008.py:293:52: B006 [*] Do not use mutable data structures for argument defaults
|
293 | def single_line_func_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -432,7 +432,7 @@ B006_B008.py:293:52: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
290 290 | ...
291 291 |
292 292 |
@ -444,7 +444,7 @@ B006_B008.py:293:52: B006 Do not use mutable data structures for argument defaul
295 297 |
296 298 |
B006_B008.py:297:52: B006 Do not use mutable data structures for argument defaults
B006_B008.py:297:52: B006 [*] Do not use mutable data structures for argument defaults
|
297 | def single_line_func_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -453,7 +453,7 @@ B006_B008.py:297:52: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
294 294 | """Docstring"""; ...
295 295 |
296 296 |
@ -465,7 +465,7 @@ B006_B008.py:297:52: B006 Do not use mutable data structures for argument defaul
299 301 | ...
300 302 |
B006_B008.py:302:52: B006 Do not use mutable data structures for argument defaults
B006_B008.py:302:52: B006 [*] Do not use mutable data structures for argument defaults
|
302 | def single_line_func_wrong(value: dict[str, str] = {
| ____________________________________________________^
@ -476,7 +476,7 @@ B006_B008.py:302:52: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
299 299 | ...
300 300 |
301 301 |
@ -500,7 +500,7 @@ B006_B008.py:308:52: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
B006_B008.py:313:52: B006 Do not use mutable data structures for argument defaults
B006_B008.py:313:52: B006 [*] Do not use mutable data structures for argument defaults
|
313 | def single_line_func_wrong(value: dict[str, str] = {}):
| ^^ B006
@ -508,7 +508,7 @@ B006_B008.py:313:52: B006 Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
310 310 | """Docstring"""
311 311 |
312 312 |

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_extended.py:17:55: B006 Do not use mutable data structures for argument defaults
B006_extended.py:17:55: B006 [*] Do not use mutable data structures for argument defaults
|
17 | def error_due_to_missing_import(foo: ImmutableTypeA = []):
| ^^ B006
@ -9,7 +9,7 @@ B006_extended.py:17:55: B006 Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Suggested fix
14 14 | ...
15 15 |
16 16 |