string check: don't warn about octal escape sequence, warn about \o (not octal in python). Closes #111799

authorMartin Pool <mbp@google.com>
changeset720a5ebaba7d
branchdefault
phasepublic
hiddenno
parent revision#27d5a6ff3ea8 closes #113231. logging checker now looks at instances of Logger classes in addition to the base logging module.
child revision#18a43f3b1962 quick fix: use %s rather than %s will avoid crash if lineno is None. See https://bitbucket.org/logilab/pylint/pull-request/6/fixed-a-bug-in-clobber_in_except-causing
files modified by this revision
ChangeLog
checkers/format.py
test/input/func_excess_escapes.py
test/messages/func_excess_escapes.txt
# HG changeset patch
# User Martin Pool <mbp@google.com>
# Date 1361785731 -3600
# Mon Feb 25 10:48:51 2013 +0100
# Node ID 720a5ebaba7d8c0762c99ef34b835a29f78c8ca6
# Parent 27d5a6ff3ea8c51a263381c59306b66a7be2e2aa
string check: don't warn about octal escape sequence, warn about \o (not octal in python). Closes #111799

diff --git a/ChangeLog b/ChangeLog
@@ -25,10 +25,13 @@
1        (patch by Torsten Marek)
2 
3      * #113231: logging checker now looks at instances of Logger classes
4        in addition to the base logging module. (patch by Mike Bryant)
5 
6 +    * #111799: don't warn about octal escape sequence, warn about \o
7 +      which is not octal in Python (patch by Martin Pool)
8 +
9  --
10      * #115580: fix erroneous W0212 (access to protected member) on super call
11        (patch by Martin Pool)
12 
13      * #110853: fix a crash when an __init__ method in a base class has been
diff --git a/checkers/format.py b/checkers/format.py
@@ -389,11 +389,14 @@
14      name = 'string_constant'
15      __implements__ = (IRawChecker, IASTNGChecker)
16 
17      # Characters that have a special meaning after a backslash in either
18      # Unicode or byte strings.
19 -    ESCAPE_CHARACTERS = 'abfnrtvox\n\r\t\\\'\"'
20 +    ESCAPE_CHARACTERS = 'abfnrtvx\n\r\t\\\'\"01234567'
21 +
22 +    # TODO(mbp): Octal characters are quite an edge case today; people may
23 +    # prefer a separate warning where they occur.  \0 should be allowed.
24 
25      # Characters that have a special meaning after a backslash but only in
26      # Unicode strings.
27      UNICODE_ESCAPE_CHARACTERS = 'uUN'
28 
diff --git a/test/input/func_excess_escapes.py b/test/input/func_excess_escapes.py
@@ -10,11 +10,14 @@
29 
30  # Valid escape sequences.
31  NEWLINE = "\n"
32  OLD_ESCAPES = '\a\b\f\n\t\r\v'
33  HEX = '\xad\x0a\x0d'
34 -OCTAL = '\o123\o000'
35 +FALSE_OCTAL = '\o123\o000'  # Not octal in Python
36 +OCTAL = '\123\000'
37 +NOT_OCTAL = '\888\999'
38 +NUL = '\0'
39  UNICODE = u'\u1234'
40  HIGH_UNICODE = u'\U0000abcd'
41  QUOTES = '\'\"'
42  LITERAL_NEWLINE = '\
43  '
diff --git a/test/messages/func_excess_escapes.txt b/test/messages/func_excess_escapes.txt
@@ -1,8 +1,12 @@
44  W:  7: Anomalous backslash in string: '\['. String constant might be missing an r prefix.
45  W:  7: Anomalous backslash in string: '\]'. String constant might be missing an r prefix.
46  W:  8: Anomalous backslash in string: '\/'. String constant might be missing an r prefix.
47  W:  9: Anomalous backslash in string: '\`'. String constant might be missing an r prefix.
48 -W: 24: Anomalous backslash in string: '\P'. String constant might be missing an r prefix.
49 -W: 30: Anomalous Unicode escape in byte string: '\u'. String constant might be missing an r or u prefix.
50 -W: 31: Anomalous Unicode escape in byte string: '\U'. String constant might be missing an r or u prefix.
51 -W: 32: Anomalous Unicode escape in byte string: '\N'. String constant might be missing an r or u prefix.
52 +W: 15: Anomalous backslash in string: '\o'. String constant might be missing an r prefix.
53 +W: 15: Anomalous backslash in string: '\o'. String constant might be missing an r prefix.
54 +W: 17: Anomalous backslash in string: '\8'. String constant might be missing an r prefix.
55 +W: 17: Anomalous backslash in string: '\9'. String constant might be missing an r prefix.
56 +W: 27: Anomalous backslash in string: '\P'. String constant might be missing an r prefix.
57 +W: 33: Anomalous Unicode escape in byte string: '\u'. String constant might be missing an r or u prefix.
58 +W: 34: Anomalous Unicode escape in byte string: '\U'. String constant might be missing an r or u prefix.
59 +W: 35: Anomalous Unicode escape in byte string: '\N'. String constant might be missing an r or u prefix.