summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorAshley Whetter <AWhetter@users.noreply.github.com>2019-05-20 23:49:29 -0700
committerClaudiu Popa <pcmanticore@gmail.com>2019-05-21 08:49:29 +0200
commit5d0c0fa73bfc1c95f59b8d6e746117777681b260 (patch)
tree6470020d6e8f1548ae627787f94d4dc81e2246e2 /pylint
parentb38a7c80211123bcc732f97da32b77002f2bde96 (diff)
downloadpylint-git-5d0c0fa73bfc1c95f59b8d6e746117777681b260.tar.gz
Fixed pragmas on their own line after a backlash being ignored (#2923)
Closes #199
Diffstat (limited to 'pylint')
-rw-r--r--pylint/lint.py15
-rw-r--r--pylint/test/functional/pragma_after_backslash.py10
2 files changed, 25 insertions, 0 deletions
diff --git a/pylint/lint.py b/pylint/lint.py
index f1ebd1a1e..1718b03a5 100644
--- a/pylint/lint.py
+++ b/pylint/lint.py
@@ -833,7 +833,18 @@ class PyLinter(
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)
@@ -888,6 +899,10 @@ class PyLinter(
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])
diff --git a/pylint/test/functional/pragma_after_backslash.py b/pylint/test/functional/pragma_after_backslash.py
new file mode 100644
index 000000000..c506f6c9d
--- /dev/null
+++ b/pylint/test/functional/pragma_after_backslash.py
@@ -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