summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSushobhit <31987769+sushobhit27@users.noreply.github.com>2018-05-09 06:18:16 +0530
committerClaudiu Popa <pcmanticore@gmail.com>2018-05-09 02:48:16 +0200
commit8c5b74aadd2afdb1e5adbd3d8f93db9093f11d9d (patch)
tree749858cdbcd5fc79933786143bd809377c194ab6
parent4ad6362b785f8f9ba71b4df33b09fb20f9dce575 (diff)
downloadpylint-git-8c5b74aadd2afdb1e5adbd3d8f93db9093f11d9d.tar.gz
Add new check py3k invalid-unicode-literal. (#2068)
Close #1938
-rw-r--r--CONTRIBUTORS.txt3
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/python3.py7
-rw-r--r--pylint/test/unittest_checker_python3.py3
4 files changed, 17 insertions, 0 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index d9a6ad1b6..ffa4c00a8 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -152,3 +152,6 @@ Order doesn't matter (not that much, at least ;)
* Jacques Kvam: contributor
* Brian Shaginaw: prevent error on exception check for functions
+
+* Sushobhit (sushobhit27): contributor
+ Added new py3k check invalid-unicode-literal.
diff --git a/ChangeLog b/ChangeLog
index d985c8839..065bb90ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,10 @@ What's New in Pylint 1.8.4?
Release date: 2018-04-05
+ * Fix invalid string literal like a = ur'xxx' with --py3k.
+
+ Close #1938
+
* Stop early when we already detected a disable for a line too long
Close #1974
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py
index bf694de0a..630926dbd 100644
--- a/pylint/checkers/python3.py
+++ b/pylint/checkers/python3.py
@@ -976,6 +976,11 @@ class Python3TokenChecker(checkers.BaseTokenChecker):
'Used when non-ascii bytes literals are found in a program. '
'They are no longer supported in Python 3.',
{'maxversion': (3, 0)}),
+ 'E1611': ('unicode raw string literals not supported in 3.x',
+ 'invalid-unicode-literal',
+ 'Used when raw unicode literals are found in a program. '
+ 'They are no longer supported in Python 3.',
+ {'maxversion': (3, 0)}),
}
def process_tokens(self, tokens):
@@ -991,6 +996,8 @@ class Python3TokenChecker(checkers.BaseTokenChecker):
if tok_type == tokenize.STRING and token.startswith('b'):
if any(elem for elem in token if ord(elem) > 127):
self.add_message('non-ascii-bytes-literal', line=start[0])
+ if tok_type == tokenize.STRING and token.startswith('ur'):
+ self.add_message('invalid-unicode-literal', line=start[0])
def register(linter):
diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py
index 64f660b58..1538743ad 100644
--- a/pylint/test/unittest_checker_python3.py
+++ b/pylint/test/unittest_checker_python3.py
@@ -996,6 +996,9 @@ class TestPython3TokenChecker(testutils.CheckerTestCase):
def test_old_ne_operator(self):
self._test_token_message("1 <> 2", "old-ne-operator")
+ def test_invalid_string_literal(self):
+ self._test_token_message("a = ur'aaa'", 'invalid-unicode-literal')
+
def test_old_octal_literal(self):
for octal in ("045", "055", "075", "077", "076543"):
self._test_token_message(octal, "old-octal-literal")