Hello Code Quality people, I'm writing to you today about a change that I'm proposing to CPython, which will warn on invalid Unicode (and bytes) escape sequences, starting 3.6. It will eventually become an error, although when is yet to be decided. See http://bugs.python.org/issue27364 for the patch and discussion. First message sums up pretty well what the end result will be (with maybe a few minor differences). As Victor Stinner and Guido both suggested, it would be good to introduce this in the linters, to help folks who are running e.g. 3.5 (or 2.7 with plans to migrate). So here I am, asking the maintainers of the linters to introduce this, hopefully before 3.6.0 hits the shelves in December. Thanks in advance! -Emanuel
* Émanuel Barry <vgr255@live.ca> [2016-06-27 21:08:20 -0400]:
Hello Code Quality people, I'm writing to you today about a change that I'm proposing to CPython, which will warn on invalid Unicode (and bytes) escape sequences, starting 3.6. It will eventually become an error, although when is yet to be decided. See http://bugs.python.org/issue27364 for the patch and discussion. First message sums up pretty well what the end result will be (with maybe a few minor differences).
As Victor Stinner and Guido both suggested, it would be good to introduce this in the linters, to help folks who are running e.g. 3.5 (or 2.7 with plans to migrate). So here I am, asking the maintainers of the linters to introduce this, hopefully before 3.6.0 hits the shelves in December.
pylint already does: $ cat x.py print("hello \world") $ pylint x.py [...] W: 1, 0: Anomalous backslash in string: '\w'. String constant might be missing an r prefix. (anomalous-backslash-in-string) [...] Florian -- http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP) GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc I love long mails! | http://email.is-not-s.ms/
From: Florian Bruhin Sent: Tuesday, June 28, 2016 6:52 AM Subject: Re: [code-quality] Change in unicode escape sequences
pylint already does:
$ cat x.py print("hello \world")
$ pylint x.py [...] W: 1, 0: Anomalous backslash in string: '\w'. String constant might be missing an r prefix. (anomalous-backslash-in-string) [...]
Florian
Great, that's one less thing to worry about :) What about the other ones? -Emanuel
On Tue, Jun 28, 2016 at 5:57 AM, Émanuel Barry <vgr255@live.ca> wrote:
From: Florian Bruhin Sent: Tuesday, June 28, 2016 6:52 AM Subject: Re: [code-quality] Change in unicode escape sequences
pylint already does:
$ cat x.py print("hello \world")
$ pylint x.py [...] W: 1, 0: Anomalous backslash in string: '\w'. String constant might be missing an r prefix. (anomalous-backslash-in-string) [...]
Florian
Great, that's one less thing to worry about :) What about the other ones? -Emanuel
I think pydocstyle does this for docstrings by default. PyFlakes might also be a good candidate but they try to have as few checks that could cause false positives as possible.
Pydocstyle: $ cat x.py """hello \world.""" $ pydocstyle x.py x.py:1 at module level: D301: Use r""" if any backslashes in a docstring On Tue, Jun 28, 2016 at 3:45 PM, Ian Cordasco <graffatcolmingov@gmail.com> wrote:
On Tue, Jun 28, 2016 at 5:57 AM, Émanuel Barry <vgr255@live.ca> wrote:
From: Florian Bruhin Sent: Tuesday, June 28, 2016 6:52 AM Subject: Re: [code-quality] Change in unicode escape sequences
pylint already does:
$ cat x.py print("hello \world")
$ pylint x.py [...] W: 1, 0: Anomalous backslash in string: '\w'. String constant might be missing an r prefix. (anomalous-backslash-in-string) [...]
Florian
Great, that's one less thing to worry about :) What about the other ones? -Emanuel
I think pydocstyle does this for docstrings by default. PyFlakes might also be a good candidate but they try to have as few checks that could cause false positives as possible. _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
On Tue, Jun 28, 2016 at 5:45 AM, Ian Cordasco <graffatcolmingov@gmail.com> wrote:
PyFlakes might also be a good candidate but they try to have as few checks that could cause false positives as possible.
I'd be open to checking this in Pyflakes, since I can't really think of a useful reason to want invalid escapes in literals. Unused imports are in a similar boat: not an error per se, but there's very little reason you'd want one, while there are a lot of reasons you'd not want one.
participants (5)
-
Amir Rachum
-
Florian Bruhin
-
Ian Cordasco
-
Phil Frost
-
Émanuel Barry