Skip to content

RUF059 fix renames variables without checking existing variable names #18507

@dscorbett

Description

@dscorbett

Summary

The fix for unused-unpacked-variable (RUF059) can rename a variable to shadow or rebind an existing variable.

$ cat >ruf059.py <<'# EOF'
def f(_x):
    x, = "1"
    print(_x)
f("0")
# EOF

$ python ruf059.py
0

$ ruff --isolated check ruf059.py --select RUF059 --preview --unsafe-fixes --fix
Found 1 error (1 fixed, 0 remaining).

$ cat ruf059.py
def f(_x):
    _x, = "1"
    print(_x)
f("0")

$ python ruf059.py
1

Version

ruff 0.11.13 (5faf72a 2025-06-05)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions