summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pool <mbp@google.com>2013-02-25 10:48:51 +0100
committerMartin Pool <mbp@google.com>2013-02-25 10:48:51 +0100
commitf05a51fe72e24fb176b34153efb7d3a6f4218e18 (patch)
tree01292422ad3901b66a778d551f1e54ac5b43938e
parent19a54ae055682f14a7e7646538f938c959735be3 (diff)
downloadpylint-f05a51fe72e24fb176b34153efb7d3a6f4218e18.tar.gz
string check: don't warn about octal escape sequence, warn about \o (not octal in python). Closes #111799
-rw-r--r--ChangeLog3
-rw-r--r--checkers/format.py5
-rw-r--r--test/input/func_excess_escapes.py5
-rw-r--r--test/messages/func_excess_escapes.txt12
4 files changed, 19 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 1658c16..f894a5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,9 @@ ChangeLog for PyLint
* #113231: logging checker now looks at instances of Logger classes
in addition to the base logging module. (patch by Mike Bryant)
+ * #111799: don't warn about octal escape sequence, warn about \o
+ which is not octal in Python (patch by Martin Pool)
+
--
* #115580: fix erroneous W0212 (access to protected member) on super call
(patch by Martin Pool)
diff --git a/checkers/format.py b/checkers/format.py
index d45667f..82d55fe 100644
--- a/checkers/format.py
+++ b/checkers/format.py
@@ -391,7 +391,10 @@ class StringConstantChecker(BaseRawChecker):
# Characters that have a special meaning after a backslash in either
# Unicode or byte strings.
- ESCAPE_CHARACTERS = 'abfnrtvox\n\r\t\\\'\"'
+ ESCAPE_CHARACTERS = 'abfnrtvx\n\r\t\\\'\"01234567'
+
+ # TODO(mbp): Octal characters are quite an edge case today; people may
+ # prefer a separate warning where they occur. \0 should be allowed.
# Characters that have a special meaning after a backslash but only in
# Unicode strings.
diff --git a/test/input/func_excess_escapes.py b/test/input/func_excess_escapes.py
index fe3dc11..e3483d6 100644
--- a/test/input/func_excess_escapes.py
+++ b/test/input/func_excess_escapes.py
@@ -12,7 +12,10 @@ ESCAPE_BACKSLASH = '\`'
NEWLINE = "\n"
OLD_ESCAPES = '\a\b\f\n\t\r\v'
HEX = '\xad\x0a\x0d'
-OCTAL = '\o123\o000'
+FALSE_OCTAL = '\o123\o000' # Not octal in Python
+OCTAL = '\123\000'
+NOT_OCTAL = '\888\999'
+NUL = '\0'
UNICODE = u'\u1234'
HIGH_UNICODE = u'\U0000abcd'
QUOTES = '\'\"'
diff --git a/test/messages/func_excess_escapes.txt b/test/messages/func_excess_escapes.txt
index aad9ebc..173b108 100644
--- a/test/messages/func_excess_escapes.txt
+++ b/test/messages/func_excess_escapes.txt
@@ -2,7 +2,11 @@ W: 7: Anomalous backslash in string: '\['. String constant might be missing an
W: 7: Anomalous backslash in string: '\]'. String constant might be missing an r prefix.
W: 8: Anomalous backslash in string: '\/'. String constant might be missing an r prefix.
W: 9: Anomalous backslash in string: '\`'. String constant might be missing an r prefix.
-W: 24: Anomalous backslash in string: '\P'. String constant might be missing an r prefix.
-W: 30: Anomalous Unicode escape in byte string: '\u'. String constant might be missing an r or u prefix.
-W: 31: Anomalous Unicode escape in byte string: '\U'. String constant might be missing an r or u prefix.
-W: 32: Anomalous Unicode escape in byte string: '\N'. String constant might be missing an r or u prefix.
+W: 15: Anomalous backslash in string: '\o'. String constant might be missing an r prefix.
+W: 15: Anomalous backslash in string: '\o'. String constant might be missing an r prefix.
+W: 17: Anomalous backslash in string: '\8'. String constant might be missing an r prefix.
+W: 17: Anomalous backslash in string: '\9'. String constant might be missing an r prefix.
+W: 27: Anomalous backslash in string: '\P'. String constant might be missing an r prefix.
+W: 33: Anomalous Unicode escape in byte string: '\u'. String constant might be missing an r or u prefix.
+W: 34: Anomalous Unicode escape in byte string: '\U'. String constant might be missing an r or u prefix.
+W: 35: Anomalous Unicode escape in byte string: '\N'. String constant might be missing an r or u prefix.