New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add autofix for W605 [InvalidEscapeSequence] #1361
Conversation
This solution does not seem pythonic to me. I believe the use of
There is also a Windows path corner case when the fixer should not run or the fixer should add
|
@cclauss Docstrings are not exempt from the normal Python syntax rules about string literals. If you want to include a Windows path in a docstring, you still need to escape the backslashes (
So ignoring W605 is not a good plan. |
The leading
I have no problem with |
It’s acceptable to Ruff too. Just because the autofixer wants to fix it one way doesn’t mean you’re not allowed to fix it a different way! The main reason the autofixer has to go with |
Please reread the first few paragraphs of https://docs.python.org/3/library/re.html If my string is being flagged for having an invalid escape sequence then the fixer does not need to read my mind. It just needs to suggest that I do what the Python docs recommend in that situation. Those docs explicitly say that substituting ever more backslashes only confuses the reader. |
What I’m saying is that if the autofixer were to change ❯ python3 -Wd
Python 3.10.10 (main, Feb 7 2023, 12:19:31) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s = """C:\documents, D:\readme"""
<stdin>:1: DeprecationWarning: invalid escape sequence '\d'
>>> s == """C:\\documents, D:\readme"""
True
>>> s == r"""C:\documents, D:\readme"""
False |
Nice example. I understand now. Thanks. |
I added the autofix, updated the README, and updated the insta tests.