B018 doesn't trigger for useless expressions involving multiple variables
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 123
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 5
Description
I recently ran into the following bug and was surprised it wasn't flagged by B018:
def some_funcion(a, b, c, d):
result = a * b
+c * d
return result
that should have been
def some_funcion(a, b, c, d):
result = (
a * b
+ c * d
)
return result
It looks like B018 doesn't trigger for expressions containing multiple variables.
Here's some examples:
a * b # doesn't trigger B018
+a * b # doesn't trigger B018
+1 * 2 # doesn't trigger B018
-1 * 2 # doesn't trigger B018
1 * 2 + 3 # doesn't trigger B018
a + 1 # doesn't trigger B018
a # triggers B018
(a, b) # triggers B018
1 # triggers B018
+1 # triggers B018
-1 # triggers B018
Versions I'm using:
python version 3.10.13
flake8 version 7.0.0
flake8-bugbear version 23.12.2
ruff version 0.1.13
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
Start by locating the B018 implementation and its existing tests, then reproduce the listed expressions with the reported Python, flake8-bugbear, and Ruff versions. Extend the B018 behavior so the multi-variable expressions described in the issue are flagged, and verify the existing triggering examples remain covered.
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
- 45/100