PyCQA / PyCQA/flake8-bugbear

B018 doesn't trigger for useless expressions involving multiple variables

Open
#452 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.