Skip to content

Commit 8b734d9

Browse files
committed
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.
1 parent 5d24e16 commit 8b734d9

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

pep8.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,8 @@ def maybe_check_physical(self, token):
13631363
# *not* check the last line: its newline is outside of the
13641364
# multiline string, so we consider it a regular physical line
13651365
# (it will be checked when we see the newline token).
1366+
if noqa(token[4]):
1367+
return
13661368
self.multiline = True
13671369
self.line_number = token[2][0]
13681370
for line in token[1].split('\n')[:-1]:

testsuite/W19.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ def long_function_name(
105105
with tabs
106106
and spaces
107107
'''
108+
#: Okay
109+
'''sometimes, you just need to go nuts in a multiline string
110+
and allow all sorts of crap
111+
like mixed tabs and spaces
112+
113+
or trailing whitespace
114+
or long long long long long long long long long long long long long long long long long lines
115+
''' # nopep8
116+
#: Okay
117+
'''this one
118+
will get no warning
119+
even though the noqa comment is not immediately after the string
120+
''' + foo # noqa
121+
#
108122
#: E101 W191
109123
if foo is None and bar is "frop" and \
110124
blah == 'yeah':

0 commit comments

Comments
 (0)