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; Identifier naming conventions
9
10((identifier) @type.class
11 (#match? @type.class "^[A-Z]"))
12
13((identifier) @constant
14 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
15
16; TypeVar with constraints in type parameters
17(type
18 (tuple (identifier) @type)
19)
20
21; Function calls
22
23(decorator
24 "@" @punctuation.special
25 (identifier) @function.decorator)
26
27(call
28 function: (attribute attribute: (identifier) @function.method.call))
29(call
30 function: (identifier) @function.call)
31
32; Function and class definitions
33
34(function_definition
35 name: (identifier) @function.definition)
36
37; Class definitions and calling: needs to come after the regex matching above
38
39(class_definition
40 name: (identifier) @type.class.definition)
41
42(call
43 function: (identifier) @type.class.call
44 (#match? @type.class.call "^[A-Z][A-Z0-9_]*[a-z]"))
45
46; Builtin functions
47
48((call
49 function: (identifier) @function.builtin)
50 (#match?
51 @function.builtin
52 "^(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__)$"))
53
54; Literals
55
56[
57 (none)
58 (true)
59 (false)
60 (ellipsis)
61] @constant.builtin
62
63[
64 (integer)
65 (float)
66] @number
67
68; Self references
69
70[
71 (parameters (identifier) @variable.special)
72 (attribute (identifier) @variable.special)
73 (#match? @variable.special "^self|cls$")
74]
75
76(comment) @comment
77(string) @string
78(escape_sequence) @string.escape
79
80[
81 "("
82 ")"
83 "["
84 "]"
85 "{"
86 "}"
87] @punctuation.bracket
88
89(interpolation
90 "{" @punctuation.special
91 "}" @punctuation.special) @embedded
92
93; Docstrings.
94(function_definition
95 "async"?
96 "def"
97 name: (_)
98 (parameters)?
99 body: (block (expression_statement (string) @string.doc)))
100
101[
102 "-"
103 "-="
104 "!="
105 "*"
106 "**"
107 "**="
108 "*="
109 "/"
110 "//"
111 "//="
112 "/="
113 "&"
114 "%"
115 "%="
116 "^"
117 "+"
118 "->"
119 "+="
120 "<"
121 "<<"
122 "<="
123 "<>"
124 "="
125 ":="
126 "=="
127 ">"
128 ">="
129 ">>"
130 "|"
131 "~"
132 "and"
133 "in"
134 "is"
135 "not"
136 "or"
137 "is not"
138 "not in"
139] @operator
140
141[
142 "as"
143 "assert"
144 "async"
145 "await"
146 "break"
147 "class"
148 "continue"
149 "def"
150 "del"
151 "elif"
152 "else"
153 "except"
154 "exec"
155 "finally"
156 "for"
157 "from"
158 "global"
159 "if"
160 "import"
161 "lambda"
162 "nonlocal"
163 "pass"
164 "print"
165 "raise"
166 "return"
167 "try"
168 "while"
169 "with"
170 "yield"
171 "match"
172 "case"
173] @keyword