Skip to content

RUF052 fix is unsafe when renaming function parameters #14790

@dscorbett

Description

@dscorbett

The fix for used-dummy-variable (RUF052) in Ruff 0.8.2 can introduce errors when renaming a function parameter. It should be marked unsafe in that context unless the parameter is positional-only.

$ cat ruf052.py
def f(_x):
    return _x
print(f(_x=1))

$ python ruf052.py
1

$ ruff check --isolated --preview --select RUF052 ruf052.py --fix
Found 1 error (1 fixed, 0 remaining).

$ cat ruf052.py
def f(x):
    return x
print(f(_x=1))

$ python ruf052.py
Traceback (most recent call last):
  File "ruf052.py", line 3, in <module>
    print(f(_x=1))
          ^^^^^^^
TypeError: f() got an unexpected keyword argument '_x'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationspreviewRelated to preview mode features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions