---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B008 Do not perform function call `range` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:102:61
    |
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
    |

B008 Do not perform function call `range` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:106:64
    |
106 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}):
    |                                                                ^^^^^^^^
107 |     pass
    |

B008 Do not perform function call `range` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:110:60
    |
110 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
    |                                                            ^^^^^^^^
111 |     pass
    |

B008 Do not perform function call `time.time` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:126:39
    |
124 | # B008
125 | # Flag function calls as default args (including if they are part of a sub-expression)
126 | def in_fact_all_calls_are_wrong(value=time.time()):
    |                                       ^^^^^^^^^^^
127 |     ...
    |

B008 Do not perform function call `dt.datetime.now` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:130:12
    |
130 | def f(when=dt.datetime.now() + dt.timedelta(days=7)):
    |            ^^^^^^^^^^^^^^^^^
131 |     pass
    |

B008 Do not perform function call in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:134:30
    |
134 | def can_even_catch_lambdas(a=(lambda x: x)()):
    |                              ^^^^^^^^^^^^^^^
135 |     ...
    |

B008 Do not perform function call `dt.datetime.now` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:242:31
    |
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
    |

B008 Do not perform function call `map` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:248:22
    |
246 | # Don't flag nested B006 since we can't guarantee that
247 | # it isn't made mutable by the outer operation.
248 | def no_nested_b006(a=map(lambda s: s.upper(), ["a", "b", "c"])):
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
249 |     pass
    |

B008 Do not perform function call `random.randint` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:253:19
    |
252 | # B008-ception.
253 | def nested_b008(a=random.randint(0, dt.datetime.now().year)):
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
254 |     pass
    |

B008 Do not perform function call `dt.datetime.now` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
   --> B006_B008.py:253:37
    |
252 | # B008-ception.
253 | def nested_b008(a=random.randint(0, dt.datetime.now().year)):
    |                                     ^^^^^^^^^^^^^^^^^
254 |     pass
    |
