This is the same issue as https://github.com/PyCQA/pycodestyle/issues/822 and https://github.com/PyCQA/pycodestyle/issues/795, it is giving the same error.
import re
def test_regex_function():
"""
Return compiled regex of which allows to process only specific file
paths or extensions, e.g. r"^.*\.svg$".
:return:
"""
return re.compile(r"^.*\.svg$")
Error:
W605 invalid escape sequence '\.'
Version:
$ pycodestyle --version
2.5.0
It was supposed to be fixed by https://github.com/PyCQA/pycodestyle/pull/818 and merged to the master. However, the error persists. Any workarounds?
The lint is correct here, that docstring will become a syntax error in 3.8
You want to prefix your docstring with an r to make it a raw string or escape your backslash
The linked PR only corrects the position of the error message
If you'd like a tool which will autofix this, one of the automatic rewrites of pyupgrade covers this
@asottile ah thanks for the clarification. So, in 3.8 this docstring would also give a syntax error?
def foo():
"""add C:\Program Files\Git\bin on Windows to the PATH"""
pass
Currently giving
W605 invalid escape sequence '\P'
W605 invalid escape sequence '\G'
yes, that one will as well
in fact today it produces what you probably wouldn't expect due to \b:
>>> foo.__doc__
'add C:\\Program Files\\Git\x08in on Windows to the PATH'
>>> print(foo.__doc__)
add C:\Program Files\Giin on Windows to the PATH
If you want to see the py38 behaviour and have access to py36 / py37 you can use:
$ python3.7 -Werror -c '"""foo\qar"""'
File "<string>", line 1
SyntaxError: invalid escape sequence \q
Ah brilliant, thanks a ton for clarifying!
Most helpful comment
yes, that one will as well
in fact today it produces what you probably wouldn't expect due to
\b:If you want to see the py38 behaviour and have access to py36 / py37 you can use: