Fix Python font lock of chained assignment statement
authorkobarity <kobarity@gmail.com>
Fri, 24 May 2024 13:50:12 +0000 (22:50 +0900)
committerEli Zaretskii <eliz@gnu.org>
Fri, 24 May 2024 14:53:34 +0000 (17:53 +0300)
* lisp/progmodes/python.el
(python-font-lock-keywords-maximum-decoration): Allow chaining
of single assignment statements.
* test/lisp/progmodes/python-tests.el
(python-font-lock-assignment-statement-20): New test.
(Bug#71093)

lisp/progmodes/python.el
test/lisp/progmodes/python-tests.el

index 02588d756e9277cc024e4455953833bb2e357c50..051f198e19287f4f47abaadeecaced8c5d415042 100644 (file)
@@ -812,8 +812,7 @@ sign in chained assignment."
     ;;   c: Collection = {1, 2, 3}
     ;;   d: Mapping[int, str] = {1: 'bar', 2: 'baz'}
     (,(python-font-lock-assignment-matcher
-       (python-rx (or line-start ?\;) (* space)
-                  grouped-assignment-target (* space)
+       (python-rx grouped-assignment-target (* space)
                   (? ?: (* space) (+ not-simple-operator) (* space))
                   (group assignment-operator)))
      (1 font-lock-variable-name-face)
index 95db93dd5cc757fe1643d58f0e3ec3fcb5f575f9..06943e22f5b2c7352191e4474e343d66e5758f45 100644 (file)
@@ -474,6 +474,16 @@ def f(x: CustomInt) -> CustomInt:
      (136 . font-lock-operator-face) (137)
      (144 . font-lock-keyword-face) (150))))
 
+(ert-deftest python-font-lock-assignment-statement-20 ()
+  (python-tests-assert-faces
+   "a = b = c = 1"
+   '((1 . font-lock-variable-name-face) (2)
+     (3 . font-lock-operator-face) (4)
+     (5 . font-lock-variable-name-face) (6)
+     (7 . font-lock-operator-face) (8)
+     (9 . font-lock-variable-name-face) (10)
+     (11 . font-lock-operator-face) (12))))
+
 (ert-deftest python-font-lock-escape-sequence-string-newline ()
   (python-tests-assert-faces
    "'\\n'