aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el31
1 files changed, 19 insertions, 12 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 831bec7f4af..360936c9efd 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -794,6 +794,25 @@ sign in chained assignment."
794 ) 794 )
795 symbol-end) 795 symbol-end)
796 . font-lock-type-face) 796 . font-lock-type-face)
797 ;; single assignment with/without type hints, e.g.
798 ;; a: int = 5
799 ;; b: Tuple[Optional[int], Union[Sequence[str], str]] = (None, 'foo')
800 ;; c: Collection = {1, 2, 3}
801 ;; d: Mapping[int, str] = {1: 'bar', 2: 'baz'}
802 (,(python-font-lock-assignment-matcher
803 (python-rx (or line-start ?\;) (* space)
804 grouped-assignment-target (* space)
805 (? ?: (* space) (group (+ not-simple-operator)) (* space))
806 (group assignment-operator)))
807 (1 font-lock-variable-name-face)
808 (3 'font-lock-operator-face)
809 (,(python-rx symbol-name)
810 (progn
811 (when-let ((type-start (match-beginning 2)))
812 (goto-char type-start))
813 (match-end 0))
814 nil
815 (0 font-lock-type-face)))
797 ;; multiple assignment 816 ;; multiple assignment
798 ;; (note that type hints are not allowed for multiple assignments) 817 ;; (note that type hints are not allowed for multiple assignments)
799 ;; a, b, c = 1, 2, 3 818 ;; a, b, c = 1, 2, 3
@@ -826,18 +845,6 @@ sign in chained assignment."
826 (match-beginning 2)) ; limit the search until the assignment 845 (match-beginning 2)) ; limit the search until the assignment
827 nil 846 nil
828 (1 font-lock-variable-name-face))) 847 (1 font-lock-variable-name-face)))
829 ;; single assignment with type hints, e.g.
830 ;; a: int = 5
831 ;; b: Tuple[Optional[int], Union[Sequence[str], str]] = (None, 'foo')
832 ;; c: Collection = {1, 2, 3}
833 ;; d: Mapping[int, str] = {1: 'bar', 2: 'baz'}
834 (,(python-font-lock-assignment-matcher
835 (python-rx (or line-start ?\;) (* space)
836 grouped-assignment-target (* space)
837 (? ?: (* space) (+ not-simple-operator) (* space))
838 (group assignment-operator)))
839 (1 font-lock-variable-name-face)
840 (2 'font-lock-operator-face))
841 ;; special cases 848 ;; special cases
842 ;; (a) = 5 849 ;; (a) = 5
843 ;; [a] = 5, 850 ;; [a] = 5,