Skip to content

FURB187 autofix can cause breaking changes  #12267

Closed
@owenlamont

Description

FURB187 autofix causes breaking changes when applied to function arguments

I have the FURB ruleset set to autofix but found the autofix for FURB187 was breaking code when applied to arguments of functions since it was mutating objects outside of the function scope.

Example Code

def local_reverse_print_list(some_list: list[int]):
    some_list = list(reversed(some_list)) # FURB187 will fix to: some_list.reverse()
    print(f"Function shows list as: {some_list}")

a_list = [1,2,3]
local_reverse_print_list(a_list)
print(f"Original list: {a_list}") # Oops - the outside list is now mutated too after the FURB187 fix

Ruff settings (relevant subset of actual settings)

[tool.ruff.lint]
# See https://docs.astral.sh/ruff/rules/
select = [
    "FURB",
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

Ruff version

0.5.1

Activity

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

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions