From 3647645e94856344696768bef590b49a24c7ac52 Mon Sep 17 00:00:00 2001 From: kobarity Date: Fri, 24 May 2024 22:50:12 +0900 Subject: [PATCH] Fix Python font lock of chained assignment statement * 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 | 3 +-- test/lisp/progmodes/python-tests.el | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 02588d756e9..051f198e192 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 95db93dd5cc..06943e22f5b 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -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' -- 2.30.2