Skip to content

False negative - FURB188 removesuffix with string literal #16231

@Skylion007

Description

@Skylion007

Description

a = "sjdfaskldjfakljklfoo"
if a.endswith("foo"):
    a = a[: -len("foo")]
print(a)

should be transformed to

a = "sjdfaskldjfakljklfoo"
a = a.removesuffx("foo")
print(a)

when FURB188 is enabled. Other similar trivial cases are caught as seen by the changes I made in PyTorch for pytorch/pytorch#146997 so I assume it's an error in the rule logic where some corner case is not properly handled.

Ruff version is ruff 0.9.6
Command is ruff check --select=FURB188 --target-version py39 test_FURB188.py

Interestingly:

a = "sjdfaskldjfakljklfoo"
suffix = "foo"
if a.endswith(suffix):
    a = a[: -len(suffix)]
print(a)

is properly flagged currently. Therefore, ruff only this issue with string literals, and only for suffixes accessed in this pattern interestingly enough.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions