---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B007 Loop control variable `i` not used within loop body
 --> B007.py:6:5
  |
4 | print(i)  # name no longer defined on Python 3; no warning yet
5 |
6 | for i in range(10):  # name not used within the loop; B007
  |     ^
7 |     print(10)
  |
help: Rename unused `i` to `_i`

B007 [*] Loop control variable `k` not used within loop body
  --> B007.py:18:13
   |
16 | for i in range(10):
17 |     for j in range(10):
18 |         for k in range(10):  # k not used, i and j used transitively
   |             ^
19 |             print(i + j)
   |
help: Rename unused `k` to `_k`
   |
17 |     for j in range(10):
   -         for k in range(10):  # k not used, i and j used transitively
18 +         for _k in range(10):  # k not used, i and j used transitively
19 |             print(i + j)
   |
note: This is an unsafe fix and may change runtime behavior

B007 Loop control variable `i` not used within loop body
  --> B007.py:30:5
   |
30 | for i, (j, (k, l)) in strange_generator():  # i, k not used
   |     ^
31 |     print(j, l)
   |
help: Rename unused `i` to `_i`

B007 [*] Loop control variable `k` not used within loop body
  --> B007.py:30:13
   |
30 | for i, (j, (k, l)) in strange_generator():  # i, k not used
   |             ^
31 |     print(j, l)
   |
help: Rename unused `k` to `_k`
   |
29 |
   - for i, (j, (k, l)) in strange_generator():  # i, k not used
30 + for i, (j, (_k, l)) in strange_generator():  # i, k not used
31 |     print(j, l)
   |
note: This is an unsafe fix and may change runtime behavior

B007 Loop control variable `bar` may not be used within loop body
  --> B007.py:34:10
   |
33 | FMT = "{foo} {bar}"
34 | for foo, bar in [(1, 2)]:
   |          ^^^
35 |     if foo:
36 |         print(FMT.format(**locals()))
   |
help: Rename unused `bar` to `_bar`

B007 Loop control variable `bar` may not be used within loop body
  --> B007.py:38:10
   |
36 |         print(FMT.format(**locals()))
37 |
38 | for foo, bar in [(1, 2)]:
   |          ^^^
39 |     if foo:
40 |         print(FMT.format(**globals()))
   |
help: Rename unused `bar` to `_bar`

B007 Loop control variable `bar` may not be used within loop body
  --> B007.py:42:10
   |
40 |         print(FMT.format(**globals()))
41 |
42 | for foo, bar in [(1, 2)]:
   |          ^^^
43 |     if foo:
44 |         print(FMT.format(**vars()))
   |
help: Rename unused `bar` to `_bar`

B007 Loop control variable `bar` may not be used within loop body
  --> B007.py:46:10
   |
44 |         print(FMT.format(**vars()))
45 |
46 | for foo, bar in [(1, 2)]:
   |          ^^^
47 |     print(FMT.format(foo=foo, bar=eval("bar")))
   |
help: Rename unused `bar` to `_bar`

B007 [*] Loop control variable `bar` not used within loop body
  --> B007.py:52:14
   |
50 | def f():
51 |     # Fixable.
52 |     for foo, bar, baz in (["1", "2", "3"],):
   |              ^^^
53 |         if foo or baz:
54 |             break
   |
help: Rename unused `bar` to `_bar`
   |
51 |     # Fixable.
   -     for foo, bar, baz in (["1", "2", "3"],):
52 +     for foo, _bar, baz in (["1", "2", "3"],):
53 |         if foo or baz:
   |
note: This is an unsafe fix and may change runtime behavior

B007 Loop control variable `bar` not used within loop body
  --> B007.py:59:14
   |
57 | def f():
58 |     # Unfixable due to usage of `bar` outside of loop.
59 |     for foo, bar, baz in (["1", "2", "3"],):
   |              ^^^
60 |         if foo or baz:
61 |             break
   |
help: Rename unused `bar` to `_bar`

B007 [*] Loop control variable `bar` not used within loop body
  --> B007.py:68:14
   |
66 | def f():
67 |     # Fixable.
68 |     for foo, bar, baz in (["1", "2", "3"],):
   |              ^^^
69 |         if foo or baz:
70 |             break
   |
help: Rename unused `bar` to `_bar`
   |
67 |     # Fixable.
   -     for foo, bar, baz in (["1", "2", "3"],):
68 +     for foo, _bar, baz in (["1", "2", "3"],):
69 |         if foo or baz:
   |
note: This is an unsafe fix and may change runtime behavior

B007 Loop control variable `bar` not used within loop body
  --> B007.py:77:14
   |
75 | def f():
76 |     # Unfixable.
77 |     for foo, bar, baz in (["1", "2", "3"],):
   |              ^^^
78 |         if foo or baz:
79 |             break
   |
help: Rename unused `bar` to `_bar`

B007 Loop control variable `bar` not used within loop body
  --> B007.py:88:14
   |
86 | def f():
87 |     # Unfixable (false negative) due to usage of `bar` outside of loop.
88 |     for foo, bar, baz in (["1", "2", "3"],):
   |              ^^^
89 |         if foo or baz:
90 |             break
   |
help: Rename unused `bar` to `_bar`

B007 Loop control variable `line_` not used within loop body
  --> B007.py:98:5
   |
96 | # Unfixable due to trailing underscore (`_line_` wouldn't be considered an ignorable
97 | # variable name).
98 | for line_ in range(self.header_lines):
   |     ^^^^^
99 |     fp.readline()
   |
