Closed
Description
Description
The fix for unnecessary-dunder-call
(PLC2801) in Ruff 0.9.3 can change the program’s behavior when the rewritten expression is followed by an attribute access or a subscript access. The fix should wrap the rewritten expression in parentheses in those contexts.
$ cat >plc2801.py <<'#EOF'
print(1j.__add__(1.0).real)
print("x".__add__("y")[0])
#EOF
$ python plc2801.py
1.0
x
$ ruff --isolated check --preview --select PLC2801 plc2801.py --unsafe-fixes --fix
Found 2 errors (2 fixed, 0 remaining).
$ cat plc2801.py
print(1j + 1.0.real)
print("x" + "y"[0])
$ python plc2801.py
(1+1j)
xy