summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkobarity <kobarity@gmail.com>2024-05-24 22:50:12 +0900
committerEli Zaretskii <eliz@gnu.org>2024-05-24 17:53:34 +0300
commit3647645e94856344696768bef590b49a24c7ac52 (patch)
tree783610e7ae81fc493a09a28f0e22f3208d39717e
parent3291dea441f25ca14619bebe493ffb694f53cf9d (diff)
downloademacs-3647645e94856344696768bef590b49a24c7ac52.tar.gz
emacs-3647645e94856344696768bef590b49a24c7ac52.tar.bz2
emacs-3647645e94856344696768bef590b49a24c7ac52.zip
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)
-rw-r--r--lisp/progmodes/python.el3
-rw-r--r--test/lisp/progmodes/python-tests.el10
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'