emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 34c14430e9d: Don't misindent 'else:' after 'if re.match:' in Py


From: Dmitry Gutov
Subject: emacs-29 34c14430e9d: Don't misindent 'else:' after 'if re.match:' in Python
Date: Wed, 8 Mar 2023 15:50:35 -0500 (EST)

branch: emacs-29
commit 34c14430e9d070ffc98527fc95677dd5c5758536
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    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>
---
 lisp/progmodes/python.el            |  4 +++-
 test/lisp/progmodes/python-tests.el | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 1f970633bfc..81475f31f60 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -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))
diff --git a/test/lisp/progmodes/python-tests.el 
b/test/lisp/progmodes/python-tests.el
index 4f24c042c6a..6928e313dc4 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -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
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]