summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryce Guinta <bryce.paul.guinta@gmail.com>2018-07-13 11:14:51 -0600
committerClaudiu Popa <pcmanticore@gmail.com>2018-07-15 09:26:22 +0200
commit49e7a2ad9cf3636968a4612ad08bdc4126fcba73 (patch)
tree4be9294158c04b01e99be993797afef3c238c86d
parent25ffb2f3dee11854ec7a50203c62e230df085001 (diff)
downloadpylint-git-49e7a2ad9cf3636968a4612ad08bdc4126fcba73.tar.gz
Fix incorrect hanging indent detection for with statements
Add with statement to recognized token keywords for format checker. Also recognize with statement as the start of a block to allow deeper indentation for hanging continuation Close #461
-rw-r--r--ChangeLog4
-rw-r--r--doc/whatsnew/2.0.rst2
-rw-r--r--pylint/checkers/format.py4
-rw-r--r--pylint/test/functional/bad_continuation.py13
4 files changed, 20 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e736e3df7..f70654b25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -90,6 +90,10 @@ Release date: |TBA|
Close #1950
+ * Fix false-positive ``bad-continuation`` for with statements
+
+ Close #461
+
* Don't warn about `stop-iteration-return` when using `next()` over `itertools.count`
Close #2158
diff --git a/doc/whatsnew/2.0.rst b/doc/whatsnew/2.0.rst
index df8085585..c6f2b4022 100644
--- a/doc/whatsnew/2.0.rst
+++ b/doc/whatsnew/2.0.rst
@@ -334,6 +334,8 @@ Other Changes
this might actually cause bugs, so if you want to check for ``None`` values
as well, pass ``--ignore-none=n`` to pylint.
+* Fix false-positive ``bad-continuation`` for with statements
+
* Fix false-positive ``bad-whitespace`` message for typing annoatations
with ellipses in them
diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py
index 21f6b5d84..91bbb3448 100644
--- a/pylint/checkers/format.py
+++ b/pylint/checkers/format.py
@@ -47,9 +47,9 @@ from pylint.checkers.utils import check_messages
from pylint.utils import WarningScope, OPTION_RGX
_ASYNC_TOKEN = 'async'
-_CONTINUATION_BLOCK_OPENERS = ['elif', 'except', 'for', 'if', 'while', 'def', 'class']
+_CONTINUATION_BLOCK_OPENERS = ['elif', 'except', 'for', 'if', 'while', 'def', 'class', 'with']
_KEYWORD_TOKENS = ['assert', 'del', 'elif', 'except', 'for', 'if', 'in', 'not',
- 'raise', 'return', 'while', 'yield']
+ 'raise', 'return', 'while', 'yield', 'with']
if sys.version_info < (3, 0):
_KEYWORD_TOKENS.append('print')
diff --git a/pylint/test/functional/bad_continuation.py b/pylint/test/functional/bad_continuation.py
index 34292abe0..e78f8d5e0 100644
--- a/pylint/test/functional/bad_continuation.py
+++ b/pylint/test/functional/bad_continuation.py
@@ -1,5 +1,5 @@
"""Regression test case for bad-continuation."""
-# pylint: disable=print-statement,using-constant-test
+# pylint: disable=print-statement,using-constant-test,missing-docstring,wrong-import-position
# Various alignment for brackets
from __future__ import print_function
@@ -189,3 +189,14 @@ continue2("foo",
some_other_arg="this "
"is "
"fine")
+
+from contextlib import contextmanager
+@contextmanager
+def mycontext(*args):
+ yield args
+
+with mycontext(
+ "this is",
+ "great stuff",
+ "mane"):
+ pass