---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:27:37
   |
25 |     for shopper in shoppers:
26 |         shopper = shopper.title()
27 |         collect_shop_items(shopper, section_items)  # B031
   |                                     ^^^^^^^^^^^^^
28 |     # We're outside the nested loop and used the group again.
29 |     collect_shop_items(shopper, section_items)  # B031
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:29:33
   |
27 |         collect_shop_items(shopper, section_items)  # B031
28 |     # We're outside the nested loop and used the group again.
29 |     collect_shop_items(shopper, section_items)  # B031
   |                                 ^^^^^^^^^^^^^
30 |
31 | for _section, section_items in groupby(items, key=lambda p: p[1]):
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:33:31
   |
31 | for _section, section_items in groupby(items, key=lambda p: p[1]):
32 |     collect_shop_items("Jane", section_items)
33 |     collect_shop_items("Joe", section_items)  # B031
   |                               ^^^^^^^^^^^^^
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:40:37
   |
38 |     countdown = 3
39 |     while countdown > 0:
40 |         collect_shop_items(shopper, section_items)  # B031
   |                                     ^^^^^^^^^^^^^
41 |         countdown -= 1
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:46:29
   |
44 | collection = []
45 | for _section, section_items in groupby(items, key=lambda p: p[1]):
46 |     collection.append([list(section_items) for _ in range(3)])  # B031
   |                             ^^^^^^^^^^^^^
47 |
48 | unique_items = set()
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:56:17
   |
55 |     # But it should be detected when used again
56 |     for item in section_items:  # B031
   |                 ^^^^^^^^^^^^^
57 |         another_set.add(item)
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:79:37
   |
77 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
78 |     for shopper in shoppers:
79 |         collect_shop_items(shopper, section_items)  # B031
   |                                     ^^^^^^^^^^^^^
80 |
81 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:82:38
   |
81 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
82 |     _ = [collect_shop_items(shopper, section_items) for shopper in shoppers]  # B031
   |                                      ^^^^^^^^^^^^^
83 |
84 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
  --> B031.py:94:65
   |
92 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
93 |     # The iterator is being used for the second time.
94 |     _ = [(item1, item2) for item1 in section_items for item2 in section_items]  # B031
   |                                                                 ^^^^^^^^^^^^^
95 |
96 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
   |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:101:37
    |
 99 |     else:
100 |         collect_shop_items(shopper, section_items)
101 |         collect_shop_items(shopper, section_items)  # B031
    |                                     ^^^^^^^^^^^^^
102 |
103 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:108:41
    |
106 |         collect_shop_items(shopper, section_items)
107 |         if _section == "greens":
108 |             collect_shop_items(shopper, section_items)  # B031
    |                                         ^^^^^^^^^^^^^
109 |         elif _section == "frozen items":
110 |             collect_shop_items(shopper, section_items)  # B031
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:110:41
    |
108 |             collect_shop_items(shopper, section_items)  # B031
109 |         elif _section == "frozen items":
110 |             collect_shop_items(shopper, section_items)  # B031
    |                                         ^^^^^^^^^^^^^
111 |         else:
112 |             collect_shop_items(shopper, section_items)  # B031
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:112:41
    |
110 |             collect_shop_items(shopper, section_items)  # B031
111 |         else:
112 |             collect_shop_items(shopper, section_items)  # B031
    |                                         ^^^^^^^^^^^^^
113 |         collect_shop_items(shopper, section_items)  # B031
114 |     elif _section == "frozen items":
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:113:37
    |
111 |         else:
112 |             collect_shop_items(shopper, section_items)  # B031
113 |         collect_shop_items(shopper, section_items)  # B031
    |                                     ^^^^^^^^^^^^^
114 |     elif _section == "frozen items":
115 |         # Mix `match` and `if` statements
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:120:49
    |
118 |                 collect_shop_items(shopper, section_items)
119 |                 if _section == "fourth":
120 |                     collect_shop_items(shopper, section_items)  # B031
    |                                                 ^^^^^^^^^^^^^
121 |             case _:
122 |                 collect_shop_items(shopper, section_items)
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:126:33
    |
124 |         collect_shop_items(shopper, section_items)
125 |     # Now, it should detect
126 |     collect_shop_items(shopper, section_items)  # B031
    |                                 ^^^^^^^^^^^^^
127 |
128 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:135:49
    |
133 |             match shopper:
134 |                 case "Jane":
135 |                     collect_shop_items(shopper, section_items)  # B031
    |                                                 ^^^^^^^^^^^^^
136 |                 case _:
137 |                     collect_shop_items(shopper, section_items)  # B031
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:137:49
    |
135 |                     collect_shop_items(shopper, section_items)  # B031
136 |                 case _:
137 |                     collect_shop_items(shopper, section_items)  # B031
    |                                                 ^^^^^^^^^^^^^
138 |         case "frozen items":
139 |             collect_shop_items(shopper, section_items)
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:140:41
    |
138 |         case "frozen items":
139 |             collect_shop_items(shopper, section_items)
140 |             collect_shop_items(shopper, section_items)  # B031
    |                                         ^^^^^^^^^^^^^
141 |         case _:
142 |             collect_shop_items(shopper, section_items)
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:144:33
    |
142 |             collect_shop_items(shopper, section_items)
143 |     # Now, it should detect
144 |     collect_shop_items(shopper, section_items)  # B031
    |                                 ^^^^^^^^^^^^^
145 |
146 | for group in groupby(items, key=lambda p: p[1]):
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:203:41
    |
201 |         if _section == "greens":
202 |             collect_shop_items(shopper, section_items)
203 |             collect_shop_items(shopper, section_items)
    |                                         ^^^^^^^^^^^^^
204 |             return
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:215:41
    |
213 |         elif _section == "frozen items":
214 |             collect_shop_items(shopper, section_items)
215 |             collect_shop_items(shopper, section_items)
    |                                         ^^^^^^^^^^^^^
216 |
217 | # Should trigger, since only one branch has a return statement.
    |

B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
   --> B031.py:226:37
    |
224 |         elif _section == "frozen items":
225 |             collect_shop_items(shopper, section_items)
226 |         collect_shop_items(shopper, section_items)  # B031
    |                                     ^^^^^^^^^^^^^
227 |
228 | # Let's redefine the `groupby` function to make sure we pick up the correct one.
    |
