Fix Python mode error caused by incorrect indentation

* lisp/progmodes/python.el (python-indent--calculate-indentation):
Guard against negative indentation.  (Bug #65870)

* test/lisp/progmodes/python-tests.el
(python-indent-badly-indented-block-end): New test.
This commit is contained in:
kobarity 2023-09-16 23:14:45 +09:00 committed by Eli Zaretskii
parent d7be9fdbc0
commit c03cafba39
2 changed files with 10 additions and 1 deletions

View file

@ -1819,7 +1819,7 @@ possibilities can be narrowed to specific indentation points."
(`(:after-block-end . ,start)
;; Subtract one indentation level.
(goto-char start)
(- (current-indentation) python-indent-offset))
(max 0 (- (current-indentation) python-indent-offset)))
(`(:at-dedenter-block-start . ,_)
;; List all possible indentation levels from opening blocks.
(let ((opening-block-start-points

View file

@ -2149,6 +2149,15 @@ def test_re(string):
(python-tests-look-at "else:")
(should (= (python-indent-calculate-indentation) 4))))
(ert-deftest python-indent-badly-indented-block-end ()
"Test BUG 65870 regression."
(python-tests-with-temp-buffer
"
return
"
(goto-char (point-max))
(should (= (python-indent-calculate-indentation) 0))))
;;; Filling