Don't misindent 'else:' after 'if re.match:' in Python
* lisp/progmodes/python.el (python-info-dedenter-opening-block-positions): Check that the supposed block start is not a method call (bug#62031). * test/lisp/progmodes/python-tests.el (python-indent-after-re-match): New test. Co-authored-by: Lele Gaifax <lele@metapensiero.it>
This commit is contained in:
parent
8a2a554192
commit
34c14430e9
2 changed files with 15 additions and 1 deletions
|
@ -5792,7 +5792,9 @@ likely an invalid python file."
|
|||
(catch 'exit
|
||||
(while (python-nav--syntactically
|
||||
(lambda ()
|
||||
(re-search-backward (python-rx block-start) nil t))
|
||||
(cl-loop for pt = (re-search-backward (python-rx block-start) nil t)
|
||||
until (memq (char-before) '(nil ?\s ?\t ?\n))
|
||||
finally return pt))
|
||||
#'<)
|
||||
(let ((indentation (current-indentation)))
|
||||
(when (and (not (memq indentation collected-indentations))
|
||||
|
|
|
@ -1982,6 +1982,18 @@ match foo:
|
|||
(should (eq (car (python-indent-context)) :after-block-start))
|
||||
(should (= (python-indent-calculate-indentation) 8))))
|
||||
|
||||
(ert-deftest python-indent-after-re-match ()
|
||||
"Test BUG 62031 regression."
|
||||
(python-tests-with-temp-buffer
|
||||
"
|
||||
def test_re(string):
|
||||
if re.match('^[a-c]+$', string):
|
||||
print('yes')
|
||||
else:
|
||||
"
|
||||
(python-tests-look-at "else:")
|
||||
(should (= (python-indent-calculate-indentation) 4))))
|
||||
|
||||
|
||||
;;; Filling
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue