]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix test-regressions in python-ts-mode
authorJostein Kjønigsen <jostein@kjonigsen.net>
Mon, 5 May 2025 07:45:36 +0000 (09:45 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 10 May 2025 08:49:50 +0000 (10:49 +0200)
* 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
test/lisp/progmodes/python-tests.el

index ee014549c7fd9ee22adae9817d5a3ad954a4eefd..66f911ac697c51cae6ac3fe69990ea968317ccc1 100644 (file)
@@ -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)
index 6f9ce8c1cbb5e52a1ebc3d45cdf3dd35f3e415fd..5f264cb27c582e57536a99420904937a1f24f8c0 100644 (file)
@@ -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)