Skip to content
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

Python 2.6: false positive W605 invalid escape sequence #755

Closed
jwilk opened this issue Apr 16, 2018 · 12 comments
Closed

Python 2.6: false positive W605 invalid escape sequence #755

jwilk opened this issue Apr 16, 2018 · 12 comments

Comments

Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
@jwilk
Copy link
Contributor

@jwilk jwilk commented Apr 16, 2018

I'm getting this false positive:

$ echo 'br"\s"' | python2.6 -m pycodestyle /dev/stdin
/dev/stdin:1:3: W605 invalid escape sequence '\s'

I suspect this is caused by Python issue #15054.

You may want to disable W605 for Python 2.6.

jwilk added a commit to jwilk/python-djvulibre that referenced this issue Apr 16, 2018
Fixes false positive:

    ./tests/test_decode.py:414:19: W605 invalid escape sequence '\s'

PyCQA/pycodestyle#755
@sigmavirus24
Copy link
Member

@sigmavirus24 sigmavirus24 commented Apr 19, 2018

I don't think our checks are specific to Python versions. That said, I think the error message could be improved. And a PR to clarify what's "invalid" about it (for Python 3.7) is needed. That would allow folks to --ignore W605 if they never plan to use Python 3.7

@seeeturtle
Copy link

@seeeturtle seeeturtle commented Apr 25, 2018

@sigmavirus24, afaik, the warning is changed since python 3.6
(Note https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals)
isn't it?

@sigmavirus24
Copy link
Member

@sigmavirus24 sigmavirus24 commented Apr 25, 2018

I'm sorry @seeeturtle, could you rephrase? I'm having trouble understanding your question.

@seeeturtle
Copy link

@seeeturtle seeeturtle commented Apr 25, 2018

Sorry for too short explanation

Changed in version 3.6: Unrecognized escape sequences produce a DeprecationWarning. In some future version of Python they will be a SyntaxError.

https://bugs.python.org/issue27364

https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior

Based on the above three, I thought that the patch of rasing DeprecationWarning for invalid escape sequence is changed since python 3.6.
However, your comment seems to mean to ignore python under 3.7 not 3.6.

Am I talking right?

@sigmavirus24

@sigmavirus24
Copy link
Member

@sigmavirus24 sigmavirus24 commented Apr 25, 2018

Oh sorry, I think my earlier comments were too short too 😃 Thanks for explaining what you were saying.

So, the warning was introduced in 3.6 but those escape sequences aren't invalid yet. I think we added the check because the invalid syntax error was going to be introduced in 3.7. Also, while discussing misunderstandings: I misunderstood what @jwilk was suggesting was the problem here. The problem here is how python 2.6 tokenizes bytestrings. I think we can fix that easily Sorry for the confusion.

sigmavirus24 added a commit to sigmavirus24/pep8 that referenced this issue Apr 25, 2018
Python 2.6 has a bug (https://bugs.python.org/issue15054) that prevents
us from tokenizing strings properly that are b'' strings. This means we
cannot reliably detect future deprecated escape sequences on 2.6

Closes PyCQAgh-755
sigmavirus24 added a commit to sigmavirus24/pep8 that referenced this issue Apr 25, 2018
Python 2.6 has a bug (https://bugs.python.org/issue15054) that prevents
us from tokenizing strings properly that are b'' strings. This means we
cannot reliably detect future deprecated escape sequences on 2.6

Closes PyCQAgh-755
@seeeturtle
Copy link

@seeeturtle seeeturtle commented Apr 25, 2018

No problem :)
Btw, maybe I can send PR for modifying docs about w605 to show that it will not gonna produce error until python 3.7.

@sigmavirus24
Copy link
Member

@sigmavirus24 sigmavirus24 commented Apr 26, 2018

@seeeturtle absolutely!

@seeeturtle
Copy link

@seeeturtle seeeturtle commented Apr 27, 2018

@sigmavirus24, it seems W605 will be changed into Error starting with Python 3.8 not Python 3.7 since it breaks a lot of code.

Note:

btw, where can i add some notes for certain warning in docs?

@gdevenyi
Copy link

@gdevenyi gdevenyi commented Apr 27, 2018

This also triggers a false positive for lines defining a regex:

import re
re.match("^([-+]?\d+|^\d+%)$", string)
W605 invalid escape sequence '\d'

@FichteFoll
Copy link
Contributor

@FichteFoll FichteFoll commented Apr 27, 2018

@gdevenyi this is intended as you should be using a raw strings for regular expressions in most cases. \d is an invalid string escape sequence.

@gdevenyi
Copy link

@gdevenyi gdevenyi commented Apr 27, 2018

Hrm, okay, it works with a raw string.

@serhiy-storchaka
Copy link

@serhiy-storchaka serhiy-storchaka commented Apr 28, 2018

br"\s" doesn't contain an invalid escape sequence because it is a raw string.

The sequence \s is considered invalid only in non-raw strings.

@PyCQA PyCQA locked as off-topic and limited conversation to collaborators Apr 28, 2018
@IanLee1521 IanLee1521 closed this in 0690015 Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.