1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 04:10:54 -08:00

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.
This commit is contained in:
Jostein Kjønigsen 2025-05-05 09:45:36 +02:00 committed by Michael Albinus
parent 7cb7e96a5c
commit 9261d353cc
2 changed files with 26 additions and 6 deletions

View file

@ -1273,7 +1273,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)

View file

@ -7742,27 +7742,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)