---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006 [*] Do not use mutable data structures for argument defaults
  --> B006_B008.py:63:25
   |
63 | def this_is_wrong(value=[1, 2, 3]):
   |                         ^^^^^^^^^
64 |     ...
   |
help: Replace with `None`; initialize within function
   |
62 |
   - def this_is_wrong(value=[1, 2, 3]):
63 + def this_is_wrong(value=None):
64 |     ...
   |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
  --> B006_B008.py:67:30
   |
67 | def this_is_also_wrong(value={}):
   |                              ^^
68 |     ...
   |
help: Replace with `None`; initialize within function
   |
66 |
   - def this_is_also_wrong(value={}):
67 + def this_is_also_wrong(value=None):
68 |     ...
   |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
  --> B006_B008.py:73:52
   |
71 | class Foo:
72 |     @staticmethod
73 |     def this_is_also_wrong_and_more_indented(value={}):
   |                                                    ^^
74 |         pass
   |
help: Replace with `None`; initialize within function
   |
72 |     @staticmethod
   -     def this_is_also_wrong_and_more_indented(value={}):
73 +     def this_is_also_wrong_and_more_indented(value=None):
74 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
  --> B006_B008.py:77:31
   |
77 |   def multiline_arg_wrong(value={
   |  _______________________________^
78 | |
79 | | }):
   | |_^
80 |       ...
   |
help: Replace with `None`; initialize within function
   |
76 |
   - def multiline_arg_wrong(value={
   -
   - }):
77 + def multiline_arg_wrong(value=None):
78 |     ...
   |
note: This is an unsafe fix and may change runtime behavior

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

B006 [*] Do not use mutable data structures for argument defaults
  --> B006_B008.py:85:20
   |
85 | def and_this(value=set()):
   |                    ^^^^^
86 |     ...
   |
help: Replace with `None`; initialize within function
   |
84 |
   - def and_this(value=set()):
85 + def and_this(value=None):
86 |     ...
   |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
  --> B006_B008.py:89:20
   |
89 | def this_too(value=collections.OrderedDict()):
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^
90 |     ...
   |
help: Replace with `None`; initialize within function
   |
88 |
   - def this_too(value=collections.OrderedDict()):
89 + def this_too(value=None):
90 |     ...
   |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
  --> B006_B008.py:93:32
   |
93 | async def async_this_too(value=collections.defaultdict()):
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^
94 |     ...
   |
help: Replace with `None`; initialize within function
   |
92 |
   - async def async_this_too(value=collections.defaultdict()):
93 + async def async_this_too(value=None):
94 |     ...
   |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
  --> B006_B008.py:97:26
   |
97 | def dont_forget_me(value=collections.deque()):
   |                          ^^^^^^^^^^^^^^^^^^^
98 |     ...
   |
help: Replace with `None`; initialize within function
   |
96 |
   - def dont_forget_me(value=collections.deque()):
97 + def dont_forget_me(value=None):
98 |     ...
   |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:102:46
    |
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)]):
    |                                              ^^^^^^^^^^^^^^^^^^^^^^^^
103 |     pass
    |
help: Replace with `None`; initialize within function
    |
101 | # N.B. we're also flagging the function call in the comprehension
    - def list_comprehension_also_not_okay(default=[i**2 for i in range(3)]):
102 + def list_comprehension_also_not_okay(default=None):
103 |     pass
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:106:46
    |
106 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}):
    |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
107 |     pass
    |
help: Replace with `None`; initialize within function
    |
105 |
    - 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 |     pass
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:110:45
    |
110 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
    |                                             ^^^^^^^^^^^^^^^^^^^^^^^^
111 |     pass
    |
help: Replace with `None`; initialize within function
    |
109 |
    - def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
110 + def set_comprehension_also_not_okay(default=None):
111 |     pass
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:114:33
    |
114 | def kwonlyargs_mutable(*, value=[]):
    |                                 ^^
115 |     ...
    |
help: Replace with `None`; initialize within function
    |
113 |
    - def kwonlyargs_mutable(*, value=[]):
114 + def kwonlyargs_mutable(*, value=None):
115 |     ...
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:242:20
    |
240 | # B006 and B008
241 | # We should handle arbitrary nesting of these B008.
242 | def nested_combo(a=[float(3), dt.datetime.now()]):
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
243 |     pass
    |
help: Replace with `None`; initialize within function
    |
241 | # We should handle arbitrary nesting of these B008.
    - def nested_combo(a=[float(3), dt.datetime.now()]):
242 + def nested_combo(a=None):
243 |     pass
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:279:27
    |
278 | def mutable_annotations(
279 |     a: list[int] | None = [],
    |                           ^^
280 |     b: Optional[Dict[int, int]] = {},
281 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |
help: Replace with `None`; initialize within function
    |
278 | def mutable_annotations(
    -     a: list[int] | None = [],
279 +     a: list[int] | None = None,
280 |     b: Optional[Dict[int, int]] = {},
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:280:35
    |
278 | def mutable_annotations(
279 |     a: list[int] | None = [],
280 |     b: Optional[Dict[int, int]] = {},
    |                                   ^^
281 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
282 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |
help: Replace with `None`; initialize within function
    |
279 |     a: list[int] | None = [],
    -     b: Optional[Dict[int, int]] = {},
280 +     b: Optional[Dict[int, int]] = None,
281 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:281:62
    |
279 |     a: list[int] | None = [],
280 |     b: Optional[Dict[int, int]] = {},
281 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |                                                              ^^^^^
282 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
283 | ):
    |
help: Replace with `None`; initialize within function
    |
280 |     b: Optional[Dict[int, int]] = {},
    -     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
281 +     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = None,
282 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:282:80
    |
280 |     b: Optional[Dict[int, int]] = {},
281 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
282 |     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    |                                                                                ^^^^^
283 | ):
284 |     pass
    |
help: Replace with `None`; initialize within function
    |
281 |     c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
    -     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
282 +     d: typing_extensions.Annotated[Union[Set[str], abc.Sized], "annotation"] = None,
283 | ):
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:287:52
    |
287 | def single_line_func_wrong(value: dict[str, str] = {}):
    |                                                    ^^
288 |     """Docstring"""
    |
help: Replace with `None`; initialize within function
    |
286 |
    - def single_line_func_wrong(value: dict[str, str] = {}):
287 + def single_line_func_wrong(value: dict[str, str] = None):
288 |     """Docstring"""
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:291:52
    |
291 | def single_line_func_wrong(value: dict[str, str] = {}):
    |                                                    ^^
292 |     """Docstring"""
293 |     ...
    |
help: Replace with `None`; initialize within function
    |
290 |
    - def single_line_func_wrong(value: dict[str, str] = {}):
291 + def single_line_func_wrong(value: dict[str, str] = None):
292 |     """Docstring"""
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:296:52
    |
296 | def single_line_func_wrong(value: dict[str, str] = {}):
    |                                                    ^^
297 |     """Docstring"""; ...
    |
help: Replace with `None`; initialize within function
    |
295 |
    - def single_line_func_wrong(value: dict[str, str] = {}):
296 + def single_line_func_wrong(value: dict[str, str] = None):
297 |     """Docstring"""; ...
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:300:52
    |
300 | def single_line_func_wrong(value: dict[str, str] = {}):
    |                                                    ^^
301 |     """Docstring"""; \
302 |         ...
    |
help: Replace with `None`; initialize within function
    |
299 |
    - def single_line_func_wrong(value: dict[str, str] = {}):
300 + def single_line_func_wrong(value: dict[str, str] = None):
301 |     """Docstring"""; \
    |
note: This is an unsafe fix and may change runtime behavior

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:305:52
    |
305 |   def single_line_func_wrong(value: dict[str, str] = {
    |  ____________________________________________________^
306 | |     # This is a comment
307 | | }):
    | |_^
308 |       """Docstring"""
    |
help: Replace with `None`; initialize within function
    |
304 |
    - def single_line_func_wrong(value: dict[str, str] = {
    -     # This is a comment
    - }):
305 + def single_line_func_wrong(value: dict[str, str] = None):
306 |     """Docstring"""
    |
note: This is an unsafe fix and may change runtime behavior

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

B006 [*] Do not use mutable data structures for argument defaults
   --> B006_B008.py:316:52
    |
316 | def single_line_func_wrong(value: dict[str, str] = {}):
    |                                                    ^^
317 |     """Docstring without newline"""
    |
help: Replace with `None`; initialize within function
    |
315 |
    - def single_line_func_wrong(value: dict[str, str] = {}):
316 + def single_line_func_wrong(value: dict[str, str] = None):
317 |     """Docstring without newline"""
    |
note: This is an unsafe fix and may change runtime behavior
