From c9dbd5d64697528b38b07daa798cfe0ae65dd7f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jostein=20Kj=C3=B8nigsen?= Date: Mon, 5 May 2025 09:45:36 +0200 Subject: [PATCH] Fix test-regressions in python-ts-mode * lisp/progmodes/python.el (python--treesit-settings): Use more specific selectors for constants. * test/lisp/progmodes/python-tests.el (python-ts-mode-nested-types-face-1) (python-ts-mode-union-types-face-1) (python-ts-mode-union-types-face-2): None is now a constant. (cherry picked from commit 9261d353ccc0f94da8049faaade025f338d75354) --- lisp/progmodes/python.el | 4 +++- test/lisp/progmodes/python-tests.el | 28 +++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index ee014549c7f..66f911ac697 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1267,7 +1267,9 @@ fontified." :feature 'constant :language 'python '([(true) (false) (none)] @font-lock-constant-face - ((identifier) @font-lock-constant-face + ((assignment (identifier) @font-lock-constant-face) + (:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face)) + ((call arguments: (argument_list (identifier) @font-lock-constant-face)) (:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face)) ((attribute attribute: (identifier) @font-lock-constant-face) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 6f9ce8c1cbb..5f264cb27c5 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -7663,27 +7663,45 @@ always located at the beginning of buffer." (ert-deftest python-ts-mode-nested-types-face-1 () (python-ts-tests-with-temp-buffer "def func(v:dict[ list[ tuple[str] ], int | None] | None):" - (dolist (test '("dict" "list" "tuple" "str" "int" "None" "None")) + (dolist (test '("dict" "list" "tuple" "str" "int")) (search-forward test) (goto-char (match-beginning 0)) - (should (eq (face-at-point) 'font-lock-type-face))))) + (should (eq (face-at-point) 'font-lock-type-face))) + + (goto-char (point-min)) + (dolist (test '("None" "None")) + (search-forward test) + (goto-char (match-beginning 0)) + (should (eq (face-at-point) 'font-lock-constant-face))))) (ert-deftest python-ts-mode-union-types-face-1 () (python-ts-tests-with-temp-buffer "def f(val: tuple[tuple, list[Lvl1 | Lvl2[Lvl3[Lvl4[Lvl5 | None]], Lvl2]]]):" - (dolist (test '("tuple" "tuple" "list" "Lvl1" "Lvl2" "Lvl3" "Lvl4" "Lvl5" "None" "Lvl2")) + (dolist (test '("tuple" "tuple" "list" "Lvl1" "Lvl2" "Lvl3" "Lvl4" "Lvl5" "Lvl2")) (search-forward test) (goto-char (match-beginning 0)) - (should (eq (face-at-point) 'font-lock-type-face))))) + (should (eq (face-at-point) 'font-lock-type-face))) + + (goto-char (point-min)) + (dolist (test '("None")) + (search-forward test) + (goto-char (match-beginning 0)) + (should (eq (face-at-point) 'font-lock-constant-face))))) (ert-deftest python-ts-mode-union-types-face-2 () (python-ts-tests-with-temp-buffer "def f(val: Type0 | Type1[Type2, pack0.Type3] | pack1.pack2.Type4 | None):" - (dolist (test '("Type0" "Type1" "Type2" "Type3" "Type4" "None")) + (dolist (test '("Type0" "Type1" "Type2" "Type3" "Type4")) (search-forward test) (goto-char (match-beginning 0)) (should (eq (face-at-point) 'font-lock-type-face))) + (goto-char (point-min)) + (dolist (test '("None")) + (search-forward test) + (goto-char (match-beginning 0)) + (should (eq (face-at-point) 'font-lock-constant-face))) + (goto-char (point-min)) (dolist (test '("pack0" "pack1" "pack2")) (search-forward test) -- 2.39.5