summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Ward <greg@gerg.ca>2013-11-08 16:09:49 -0500
committerGreg Ward <greg@gerg.ca>2013-11-08 16:21:56 -0500
commit8b734d96aaefa8c054a738fa61c8e5159e7e8953 (patch)
treef27b0ce2df23a9c8ac7ee154d9471c0571e99e2e
parent5d24e16b633904135f42fbba2a4bc390e5d15a85 (diff)
downloadpep8-8b734d96aaefa8c054a738fa61c8e5159e7e8953.tar.gz
Optionally disable physical line checks inside multiline strings (issue #242)
The trick is to attach the "# nopep8" (or "# noqa") comment after the multiline string. In fact, it just has to be on the line that ends the multiline string -- like most other noqa() checks, this is a dumb scan of the physical line, not a fancy token-based check.
-rwxr-xr-xpep8.py2
-rw-r--r--testsuite/W19.py14
2 files changed, 16 insertions, 0 deletions
diff --git a/pep8.py b/pep8.py
index 032afc1..3b79091 100755
--- a/pep8.py
+++ b/pep8.py
@@ -1363,6 +1363,8 @@ class Checker(object):
# *not* check the last line: its newline is outside of the
# multiline string, so we consider it a regular physical line
# (it will be checked when we see the newline token).
+ if noqa(token[4]):
+ return
self.multiline = True
self.line_number = token[2][0]
for line in token[1].split('\n')[:-1]:
diff --git a/testsuite/W19.py b/testsuite/W19.py
index ac2095b..2209e38 100644
--- a/testsuite/W19.py
+++ b/testsuite/W19.py
@@ -105,6 +105,20 @@ if os.path.exists(os.path.join(path, PEP8_BIN)):
with tabs
and spaces
'''
+#: Okay
+'''sometimes, you just need to go nuts in a multiline string
+ and allow all sorts of crap
+ like mixed tabs and spaces
+
+or trailing whitespace
+or long long long long long long long long long long long long long long long long long lines
+''' # nopep8
+#: Okay
+'''this one
+ will get no warning
+even though the noqa comment is not immediately after the string
+''' + foo # noqa
+#
#: E101 W191
if foo is None and bar is "frop" and \
blah == 'yeah':