---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs
---
B006_B008.py:87:61: B008 Do not perform function call `range` in argument defaults
   |
87 | # N.B. we're also flagging the function call in the comprehension
88 | def list_comprehension_also_not_okay(default=[i**2 for i in range(3)]):
   |                                                             ^^^^^^^^ B008
89 |     pass
   |

B006_B008.py:91:64: B008 Do not perform function call `range` in argument defaults
   |
91 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}):
   |                                                                ^^^^^^^^ B008
92 |     pass
   |

B006_B008.py:95:60: B008 Do not perform function call `range` in argument defaults
   |
95 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
   |                                                            ^^^^^^^^ B008
96 |     pass
   |

B006_B008.py:111:39: B008 Do not perform function call `time.time` in argument defaults
    |
111 | # B008
112 | # Flag function calls as default args (including if they are part of a sub-expression)
113 | def in_fact_all_calls_are_wrong(value=time.time()):
    |                                       ^^^^^^^^^^^ B008
114 |     ...
    |

B006_B008.py:115:12: B008 Do not perform function call `dt.datetime.now` in argument defaults
    |
115 | def f(when=dt.datetime.now() + dt.timedelta(days=7)):
    |            ^^^^^^^^^^^^^^^^^ B008
116 |     pass
    |

B006_B008.py:119:30: B008 Do not perform function call in argument defaults
    |
119 | def can_even_catch_lambdas(a=(lambda x: x)()):
    |                              ^^^^^^^^^^^^^^^ B008
120 |     ...
    |

B006_B008.py:157:34: B008 Do not perform function call `float` in argument defaults
    |
157 | def float_infinity_literal(value=float("1e999")):
    |                                  ^^^^^^^^^^^^^^ B008
158 |     pass
    |

B006_B008.py:162:30: B008 Do not perform function call `float` in argument defaults
    |
162 | # But don't allow standard floats
163 | def float_int_is_wrong(value=float(3)):
    |                              ^^^^^^^^ B008
164 |     pass
    |

B006_B008.py:166:45: B008 Do not perform function call `float` in argument defaults
    |
166 | def float_str_not_inf_or_nan_is_wrong(value=float("3.14")):
    |                                             ^^^^^^^^^^^^^ B008
167 |     pass
    |

B006_B008.py:192:21: B008 Do not perform function call `float` in argument defaults
    |
192 | # B006 and B008
193 | # We should handle arbitrary nesting of these B008.
194 | def nested_combo(a=[float(3), dt.datetime.now()]):
    |                     ^^^^^^^^ B008
195 |     pass
    |

B006_B008.py:192:31: B008 Do not perform function call `dt.datetime.now` in argument defaults
    |
192 | # B006 and B008
193 | # We should handle arbitrary nesting of these B008.
194 | def nested_combo(a=[float(3), dt.datetime.now()]):
    |                               ^^^^^^^^^^^^^^^^^ B008
195 |     pass
    |

B006_B008.py:198:22: B008 Do not perform function call `map` in argument defaults
    |
198 | # Don't flag nested B006 since we can't guarantee that
199 | # it isn't made mutable by the outer operation.
200 | def no_nested_b006(a=map(lambda s: s.upper(), ["a", "b", "c"])):
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B008
201 |     pass
    |

B006_B008.py:203:19: B008 Do not perform function call `random.randint` in argument defaults
    |
203 | # B008-ception.
204 | def nested_b008(a=random.randint(0, dt.datetime.now().year)):
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B008
205 |     pass
    |

B006_B008.py:203:37: B008 Do not perform function call `dt.datetime.now` in argument defaults
    |
203 | # B008-ception.
204 | def nested_b008(a=random.randint(0, dt.datetime.now().year)):
    |                                     ^^^^^^^^^^^^^^^^^ B008
205 |     pass
    |


