Skip to content

PLR6104 misses cases with chained associative operators #11656

Description

@Avasam

The following case:

test = 1
test3 = 3
test = test * 2 * test3 * 4
96

is probably safe as:

test = 1
test3 = 3
test *= 2 * test3 * 4
96

or am I missing something?

Similarly for concatenation (which is non-commutative, but associative), seems fine here:

test = "1"
test3 = "3"
test = test + "2" + test3 + "4"
'1234'
test = "1"
test3 = "3"
test += "2" + test3 + "4"
'1234'

Example of an operator where this doesn't work (division):

test = 1
test3 = 3
test = test / 2 / test3 / 4
0.041666666666666664
test = 1
test3 = 3
test /= 2 / test3 / 4
6.0

(also just for fun, / is technically a concatenation operator for Path, but that'd require checking for the type)

ruff version 0.4.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerpreviewRelated to preview mode featuresruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions