Skip to content

Commit

Permalink
Fixed pragmas on their own line after a backlash being ignored
Browse files Browse the repository at this point in the history
Closes #199
  • Loading branch information
AWhetter committed May 18, 2019
1 parent eb37615 commit 84e8a7d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ Release date: TBA

Close #2877

* Fixed a pragma comment on its own physical line being ignored when part
of a logical line with the previous physical line.

Close #199

What's New in Pylint 2.3.0?
===========================
Expand Down
15 changes: 15 additions & 0 deletions pylint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,18 @@ def process_tokens(self, tokens):
level options
"""
control_pragmas = {"disable", "enable"}
prev_line = None
saw_newline = True
seen_newline = True
for (tok_type, content, start, _, _) in tokens:
if prev_line and prev_line != start[0]:
saw_newline = seen_newline
seen_newline = False

prev_line = start[0]
if tok_type in (tokenize.NL, tokenize.NEWLINE):
seen_newline = True

if tok_type != tokenize.COMMENT:
continue
match = OPTION_RGX.search(content)
Expand Down Expand Up @@ -887,6 +898,10 @@ def process_tokens(self, tokens):
self.add_message("file-ignored", line=start[0])
self._ignore_file = True
return
# If we did not see a newline between the previous line and now,
# we saw a backslash so treat the two lines as one.
if not saw_newline:
meth(msgid, "module", start[0] - 1)
meth(msgid, "module", start[0])
except exceptions.UnknownMessageError:
self.add_message("bad-option-value", args=msgid, line=start[0])
Expand Down
10 changes: 10 additions & 0 deletions pylint/test/functional/pragma_after_backslash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Test that a pragma has an effect when separated by a backslash."""
# pylint: disable=too-few-public-methods

class Foo:
"""block-disable test"""

def meth3(self):
"""test one line disabling"""
print(self.bla) \
# pylint: disable=E1101

0 comments on commit 84e8a7d

Please sign in to comment.