---
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
   |
63 | def this_is_wrong(value=[1, 2, 3]):
   |                         ^^^^^^^^^ B006
64 |     ...
   |
   = help: Replace with `None`; initialize within function

ℹ Unsafe fix
60 60 | # Flag mutable literals/comprehensions
61 61 | 
62 62 | 
63    |-def this_is_wrong(value=[1, 2, 3]):
   63 |+def this_is_wrong(value=None):
64 64 |     ...
65 65 | 
66 66 | 

B006_B008.py:67:30: B006 [*] Do not use mutable data structures for argument defaults
   |
67 | def this_is_also_wrong(value={}):
   |                              ^^ B006
68 |     ...
   |
   = help: Replace with `None`; initialize within function

ℹ Unsafe fix
64 64 |     ...
65 65 | 
66 66 | 
67    |-def this_is_also_wrong(value={}):
   67 |+def this_is_also_wrong(value=None):
68 68 |     ...
69 69 | 
70 70 | 

B006_B008.py:73:52: B006 [*] Do not use mutable data structures for argument defaults
   |
71 | class Foo:
72 |     @staticmethod
73 |     def this_is_also_wrong_and_more_indented(value={}):
   |                                                    ^^ B006
74 |         pass
   |
   = help: Replace with `None`; initialize within function

ℹ Unsafe fix
70 70 | 
71 71 | class Foo:
72 72 |     @staticmethod
73    |-    def this_is_also_wrong_and_more_indented(value={}):
   73 |+    def this_is_also_wrong_and_more_indented(value=None):
74 74 |         pass
75 75 | 
76 76 | 

B006_B008.py:77:31: B006 [*] Do not use mutable data structures for argument defaults
   |
77 |   def multiline_arg_wrong(value={
   |  _______________________________^
78 | | 
79 | | }):
   | |_^ B006
80 |       ...
   |
   = help: Replace with `None`; initialize within function

ℹ Unsafe fix
74 74 |         pass
75 75 | 
76 76 | 
77    |-def multiline_arg_wrong(value={
78    |-
79    |-}):
   77 |+def multiline_arg_wrong(value=None):
80 78 |     ...
81 79 | 
82 80 | def single_line_func_wrong(value = {}): ...

B006_B008.py:82:36: B006 Do not use mutable data structures for argument defaults
   |
80 |     ...
81 | 
82 | def single_line_func_wrong(value = {}): ...
   |                                    ^^ B006
   |
   = help: Replace with `None`; initialize within function

B006_B008.py:85:20: B006 [*] Do not use mutable data structures for argument defaults
   |
85 | def and_this(value=set()):
   |                    ^^^^^ B006
86 |     ...
   |
   = help: Replace with `None`; initialize within function

ℹ Unsafe fix
82 82 | def single_line_func_wrong(value = {}): ...
83 83 | 
84 84 | 
85    |-def and_this(value=set()):
   85 |+def and_this(value=None):
86 86 |     ...
87 87 | 
88 88 | 

B006_B008.py:89:20: B006 [*] Do not use mutable data structures for argument defaults
   |
89 | def this_too(value=collections.OrderedDict()):
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^ B006
90 |     ...
   |
   = help: Replace with `None`; initialize within function

ℹ Unsafe fix
86 86 |     ...
87 87 | 
88 88 | 
89    |-def this_too(value=collections.OrderedDict()):
   89 |+def this_too(value=None):
90 90 |     ...
91 91 | 
92 92 | 

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
94 |     ...
   |
   = help: Replace with `None`; initialize within function

ℹ Unsafe fix
90 90 |     ...
91 91 | 
92 92 | 
93    |-async def async_this_too(value=collections.defaultdict()):
   93 |+async def async_this_too(value=None):
94 94 |     ...
95 95 | 
96 96 | 

B006_B008.py:97:26: B006 [*] Do not use mutable data structures for argument defaults
   |
97 | def dont_forget_me(value=collections.deque()):
   |                          ^^^^^^^^^^^^^^^^^^^ B006
98 |     ...
   |
   = help: Replace with `None`; initialize within function

ℹ Unsafe fix
94 94 |     ...
95 95 | 
96 96 | 
97    |-def dont_forget_me(value=collections.deque()):
   97 |+def dont_forget_me(value=None):
98 98 |     ...
99 99 | 
100 100 | 

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)]):
    |                                              ^^^^^^^^^^^^^^^^^^^^^^^^ B006
103 |     pass
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
99  99  | 
100 100 | 
101 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)]):
    102 |+def list_comprehension_also_not_okay(default=None):
103 103 |     pass
104 104 | 
105 105 | 

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
107 |     pass
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
103 103 |     pass
104 104 | 
105 105 | 
106     |-def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}):
    106 |+def dict_comprehension_also_not_okay(default=None):
107 107 |     pass
108 108 | 
109 109 | 

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
111 |     pass
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
107 107 |     pass
108 108 | 
109 109 | 
110     |-def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
    110 |+def set_comprehension_also_not_okay(default=None):
111 111 |     pass
112 112 | 
113 113 | 

B006_B008.py:114:33: B006 [*] Do not use mutable data structures for argument defaults
    |
114 | def kwonlyargs_mutable(*, value=[]):
    |                                 ^^ B006
115 |     ...
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
111 111 |     pass
112 112 | 
113 113 | 
114     |-def kwonlyargs_mutable(*, value=[]):
    114 |+def kwonlyargs_mutable(*, value=None):
115 115 |     ...
116 116 | 
117 117 | 

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.
239 | def nested_combo(a=[float(3), dt.datetime.now()]):
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B006
240 |     pass
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
236 236 | 
237 237 | # B006 and B008
238 238 | # We should handle arbitrary nesting of these B008.
239     |-def nested_combo(a=[float(3), dt.datetime.now()]):
    239 |+def nested_combo(a=None):
240 240 |     pass
241 241 | 
242 242 | 

B006_B008.py:276:27: B006 [*] Do not use mutable data structures for argument defaults
    |
275 | def mutable_annotations(
276 |     a: list[int] | None = [],
    |                           ^^ B006
277 |     b: Optional[Dict[int, int]] = {},
278 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
273 273 | 
274 274 | 
275 275 | def mutable_annotations(
276     |-    a: list[int] | None = [],
    276 |+    a: list[int] | None = None,
277 277 |     b: Optional[Dict[int, int]] = {},
278 278 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
279 279 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),

B006_B008.py:277:35: B006 [*] Do not use mutable data structures for argument defaults
    |
275 | def mutable_annotations(
276 |     a: list[int] | None = [],
277 |     b: Optional[Dict[int, int]] = {},
    |                                   ^^ B006
278 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
279 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
274 274 | 
275 275 | def mutable_annotations(
276 276 |     a: list[int] | None = [],
277     |-    b: Optional[Dict[int, int]] = {},
    277 |+    b: Optional[Dict[int, int]] = None,
278 278 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
279 279 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
280 280 | ):

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]] = {},
278 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |                                                              ^^^^^ B006
279 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
280 | ):
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
275 275 | def mutable_annotations(
276 276 |     a: list[int] | None = [],
277 277 |     b: Optional[Dict[int, int]] = {},
278     |-    c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    278 |+    c: Annotated[Union[Set[str], abc.Sized], "annotation"] = None,
279 279 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
280 280 | ):
281 281 |     pass

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(),
279 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |                                                                                ^^^^^ B006
280 | ):
281 |     pass
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe 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(),
279     |-    d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    279 |+    d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = None,
280 280 | ):
281 281 |     pass
282 282 | 

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
285 |     """Docstring"""
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
281 281 |     pass
282 282 | 
283 283 | 
284     |-def single_line_func_wrong(value: dict[str, str] = {}):
    284 |+def single_line_func_wrong(value: dict[str, str] = None):
285 285 |     """Docstring"""
286 286 | 
287 287 | 

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
289 |     """Docstring"""
290 |     ...
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
285 285 |     """Docstring"""
286 286 | 
287 287 | 
288     |-def single_line_func_wrong(value: dict[str, str] = {}):
    288 |+def single_line_func_wrong(value: dict[str, str] = None):
289 289 |     """Docstring"""
290 290 |     ...
291 291 | 

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
294 |     """Docstring"""; ...
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
290 290 |     ...
291 291 | 
292 292 | 
293     |-def single_line_func_wrong(value: dict[str, str] = {}):
    293 |+def single_line_func_wrong(value: dict[str, str] = None):
294 294 |     """Docstring"""; ...
295 295 | 
296 296 | 

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
298 |     """Docstring"""; \
299 |         ...
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
294 294 |     """Docstring"""; ...
295 295 | 
296 296 | 
297     |-def single_line_func_wrong(value: dict[str, str] = {}):
    297 |+def single_line_func_wrong(value: dict[str, str] = None):
298 298 |     """Docstring"""; \
299 299 |         ...
300 300 | 

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] = {
    |  ____________________________________________________^
303 | |     # This is a comment
304 | | }):
    | |_^ B006
305 |       """Docstring"""
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
299 299 |         ...
300 300 | 
301 301 | 
302     |-def single_line_func_wrong(value: dict[str, str] = {
303     |-    # This is a comment
304     |-}):
    302 |+def single_line_func_wrong(value: dict[str, str] = None):
305 303 |     """Docstring"""
306 304 | 
307 305 | 

B006_B008.py:308:52: B006 Do not use mutable data structures for argument defaults
    |
308 | def single_line_func_wrong(value: dict[str, str] = {}) \
    |                                                    ^^ B006
309 |     : \
310 |     """Docstring"""
    |
    = help: Replace with `None`; initialize within function

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
314 |     """Docstring without newline"""
    |
    = help: Replace with `None`; initialize within function

ℹ Unsafe fix
310 310 |     """Docstring"""
311 311 | 
312 312 | 
313     |-def single_line_func_wrong(value: dict[str, str] = {}):
    313 |+def single_line_func_wrong(value: dict[str, str] = None):
314 314 |     """Docstring without newline"""
