W605 fix is unsafe
njzjz opened this issue · comments
Before fix:
print("\
test\.")
The original output:
$ python test_w605.py
test\.
Fix it:
$ ruff check test_w605.py --select W605 --fix --isolated
Found 1 error (1 fixed, 0 remaining).
The file becomes
print(r"\
test\.")
Run it again:
$ python test_w605.py
\
test\.
The output changes. So the fix is unsafe.
I'm sorry, I don't understand the difference between the two snippets. I something being obscured by GitHub's formatting?
Sorry I made a mistake, I fixed it.
In short, the first backslash (\
) gives different outputs with the raw string and the regular string.
>>> "\
... "
''
>>> r"\
... "
'\\\n'
Is this an unsafe fix or is this just a bug that we should fix?
Is this an unsafe fix or is this just a bug that we should fix?
I think it is a bug that should be fixed, and due to this bug, the current fix is unsafe.
Let's fix the bug rather than changing the safety.