B031 flagged on non-itertools groupby
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 123
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 5
Description
Recent B031 addition: https://github.com/PyCQA/flake8-bugbear/pull/347
A code that defines a groupby function (not itertools.groupby) will still raise B031 error.
Example:
def groupby(x, y):
return dict().items()
for _, v in groupby(None, None):
if v:
...
if v:
...
Then:
$ flake8 example.py
example.py:8:8: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage. Save the result to a list, if the result is needed multiple times.
flake8: 6.0.0, flake8-bugbear: 23.2.13
Perhaps we can have a better inspection so the error is not raised in such cases?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the supplied example with flake8 and flake8-bugbear, then locate the B031 implementation and its existing tests. Compare the handling of a locally defined groupby with itertools.groupby; done means the local function no longer produces B031 while the intended itertools.groupby warning remains covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100