---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B006_B008.py:102:61: 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
    |
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)]):
    |                                                             ^^^^^^^^ B008
103 |     pass
    |

B006_B008.py:106:64: 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
    |
106 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}):
    |                                                                ^^^^^^^^ B008
107 |     pass
    |

B006_B008.py:110:60: 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
    |
110 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
    |                                                            ^^^^^^^^ B008
111 |     pass
    |

B006_B008.py:126:39: 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
    |
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()):
    |                                       ^^^^^^^^^^^ B008
127 |     ...
    |

B006_B008.py:130:12: 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
    |
130 | def f(when=dt.datetime.now() + dt.timedelta(days=7)):
    |            ^^^^^^^^^^^^^^^^^ B008
131 |     pass
    |

B006_B008.py:134:30: 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
    |
134 | def can_even_catch_lambdas(a=(lambda x: x)()):
    |                              ^^^^^^^^^^^^^^^ B008
135 |     ...
    |

B006_B008.py:239:31: 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
    |
237 | # B006 and B008
238 | # We should handle arbitrary nesting of these B008.
239 | def nested_combo(a=[float(3), dt.datetime.now()]):
    |                               ^^^^^^^^^^^^^^^^^ B008
240 |     pass
    |

B006_B008.py:245:22: 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
    |
243 | # Don't flag nested B006 since we can't guarantee that
244 | # it isn't made mutable by the outer operation.
245 | def no_nested_b006(a=map(lambda s: s.upper(), ["a", "b", "c"])):
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B008
246 |     pass
    |

B006_B008.py:250:19: 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
    |
249 | # B008-ception.
250 | def nested_b008(a=random.randint(0, dt.datetime.now().year)):
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B008
251 |     pass
    |

B006_B008.py:250:37: 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
    |
249 | # B008-ception.
250 | def nested_b008(a=random.randint(0, dt.datetime.now().year)):
    |                                     ^^^^^^^^^^^^^^^^^ B008
251 |     pass
    |


