diff options
author | Martin Pool <mbp@google.com> | 2013-02-25 10:48:51 +0100 |
---|---|---|
committer | Martin Pool <mbp@google.com> | 2013-02-25 10:48:51 +0100 |
commit | 5b63e55160977a6c9ddbb79e32feb21197f0a915 (patch) | |
tree | a9597257adf03748181081f749932ea3b1637238 | |
parent | d0d4cf53fe5914e12acc1853e6f31ff7f3ade151 (diff) | |
download | pylint-git-5b63e55160977a6c9ddbb79e32feb21197f0a915.tar.gz |
string check: don't warn about octal escape sequence, warn about \o (not octal in python). Closes #111799
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/format.py | 5 | ||||
-rw-r--r-- | test/input/func_excess_escapes.py | 5 | ||||
-rw-r--r-- | test/messages/func_excess_escapes.txt | 12 |
4 files changed, 19 insertions, 6 deletions
@@ -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 d45667fb4..82d55feaa 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 fe3dc117e..e3483d63c 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 aad9ebca6..173b108de 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. |