Skip to content

PLR2044 fix ignores a backslash on the preceding line #19326

@dscorbett

Description

@dscorbett

Summary

The fix for empty-comment (PLR2044) deletes the entire physical line if there is nothing in the line but the comment. It should only do so when the physical line is its own logical line. When the previous line ends with a backslash, the fix should delete the comment but not the entire line, or it should delete the entire line plus the preceding backslash. Otherwise, it can change the program’s behavior. Example:

$ cat >plr2044.py <<'# EOF'
x = 0 \
#
+1
print(x)
# EOF

$ python plr2044.py
0

$ ruff --isolated check plr2044.py --select PLR2044 --fix
Found 1 error (1 fixed, 0 remaining).

$ python plr2044.py
1

Version

ruff 0.12.3 (5bc81f2 2025-07-11)

Metadata

Metadata

Assignees

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