1(attribute attribute: (identifier) @property)
2(type (identifier) @type)
3(generic_type (identifier) @type)
4
5; Type alias
6(type_alias_statement "type" @keyword)
7
8; TypeVar with constraints in type parameters
9(type
10 (tuple (identifier) @type)
11)
12
13; Function calls
14
15(decorator) @function
16
17(call
18 function: (attribute attribute: (identifier) @function.method))
19(call
20 function: (identifier) @function)
21
22; Function definitions
23
24(function_definition
25 name: (identifier) @function)
26
27; Identifier naming conventions
28
29((identifier) @type
30 (#match? @type "^[A-Z]"))
31
32((identifier) @constant
33 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
34
35; Builtin functions
36
37((call
38 function: (identifier) @function.builtin)
39 (#match?
40 @function.builtin
41 "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$"))
42
43; Literals
44
45[
46 (none)
47 (true)
48 (false)
49] @constant.builtin
50
51[
52 (integer)
53 (float)
54] @number
55
56; Self references
57
58[
59 (parameters (identifier) @variable.special)
60 (attribute (identifier) @variable.special)
61 (#match? @variable.special "^self$")
62]
63
64(comment) @comment
65(string) @string
66(escape_sequence) @string.escape
67
68[
69 "("
70 ")"
71 "["
72 "]"
73 "{"
74 "}"
75] @punctuation.bracket
76
77(interpolation
78 "{" @punctuation.special
79 "}" @punctuation.special) @embedded
80
81; Docstrings.
82(function_definition
83 "async"?
84 "def"
85 name: (_)
86 (parameters)?
87 body: (block (expression_statement (string) @string.doc)))
88
89[
90 "-"
91 "-="
92 "!="
93 "*"
94 "**"
95 "**="
96 "*="
97 "/"
98 "//"
99 "//="
100 "/="
101 "&"
102 "%"
103 "%="
104 "^"
105 "+"
106 "->"
107 "+="
108 "<"
109 "<<"
110 "<="
111 "<>"
112 "="
113 ":="
114 "=="
115 ">"
116 ">="
117 ">>"
118 "|"
119 "~"
120 "and"
121 "in"
122 "is"
123 "not"
124 "or"
125 "is not"
126 "not in"
127] @operator
128
129[
130 "as"
131 "assert"
132 "async"
133 "await"
134 "break"
135 "class"
136 "continue"
137 "def"
138 "del"
139 "elif"
140 "else"
141 "except"
142 "exec"
143 "finally"
144 "for"
145 "from"
146 "global"
147 "if"
148 "import"
149 "lambda"
150 "nonlocal"
151 "pass"
152 "print"
153 "raise"
154 "return"
155 "try"
156 "while"
157 "with"
158 "yield"
159 "match"
160 "case"
161] @keyword