Skip to content

B018 doesn't trigger for useless expressions involving multiple variables #452

Description

@swierh

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions