Fix Python builtin type highlighting (#29475)
chbk
created
| Zed 0.183.11 | With this PR |
| --- | --- |
|

|

|
```python
class A:
@classmethod
def list(cls, list: list) -> list:
return list
A.list(list())
A.list(list=list())
A.list(list=list(A.list(list())))
list: list = list()
A.list(list)
A.list(list=list)
A.list(list=A.list(list))
```
Release Notes:
- Improved Python builtin type highlighting
Change summary
crates/languages/src/python/highlights.scm | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
Detailed changes
@@ -92,9 +92,6 @@
@function.builtin
"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__"))
-((identifier) @type.builtin
- (#any-of? @type.builtin "int" "float" "complex" "bool" "list" "tuple" "range" "str" "bytes" "bytearray" "memoryview" "set" "frozenset" "dict"))
-
; Literals
[
@@ -271,24 +268,18 @@
"lambda"
] @keyword.definition
-((identifier) @attribute.builtin
+(decorator (identifier) @attribute.builtin
(#any-of? @attribute.builtin "classmethod" "staticmethod" "property"))
; Builtin types as identifiers
[
(call
function: (identifier) @type.builtin)
- (call
- arguments: (argument_list
- (identifier) @type.builtin))
- (call
- arguments: (argument_list
- (keyword_argument
- value: (identifier) @type.builtin)))
(type (identifier) @type.builtin)
+ (generic_type (identifier) @type.builtin)
; also check if type binary operator left identifier for union types
(type
(binary_operator
left: (identifier) @type.builtin))
(#any-of? @type.builtin "bool" "bytearray" "bytes" "complex" "dict" "float" "frozenset" "int" "list" "memoryview" "object" "range" "set" "slice" "str" "tuple")
-] @type.builtin
+]