Skip to content

ISC003 gives false positive depending on order of concatenation #5332

@bendoerry

Description

@bendoerry

ruff version: 0.0.275

ISC003 gives false positive depending on order of concatenation.

First Case (succeeds)

# a.py
a = "foo"

b = a + "." + "bar"
$ ruff check --isolated --select ISC a.py

Second case (fails)

# b.py
a = "foo"

b = "bar" + "." + a
$ ruff check --isolated --select ISC b.py
b.py:3:5: ISC003 Explicitly concatenated string should be implicitly concatenated
Found 1 error.

I would expect both cases to succeed.

Extra third case

# c.py
a = "foo" + "bar"
$ ruff check --isolated --select ISC c.py
c.py:1:5: ISC003 Explicitly concatenated string should be implicitly concatenated
Found 1 error.

I (personally) would also expect this to succeed. My reading of the ISC003 docs is that this is aimed at string literals that wrap over multiple lines. Which all the above cases are not.

The codebase I'm dealing with has a lot of instances of "foo" + "bar", mainly for clarity reasons, and I don't want those instances flagged. However I do still want this to be raised for multiline strings.
If flagging "foo" + "bar" is the intended behaviour, could this perhaps be made configurable? i.e. allowing single line instances like that to be ignored while still flagging the multiline cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions