python: Add dunder variables highlighting (#58158)

In the current Python Tree-sitter `highlights.scm`, dunder variables
(e.g., `__name__`, `__file__`) are not highlighted.

This PR adds a regex `#match?` so all dunder variables are highlighted
under `@attribute.special`.

An alternative solution would be to use `#any-of?` and list all dunder
variables.


| Before | After |
|
:---------------------------------------------------------------------------------------------------------------------------------:
|
:--------------------------------------------------------------------------------------------------------------------------------:
|
|<img width="623" height="895" alt="image"
src="https://github.com/user-attachments/assets/ad7b67ba-541c-40ac-a38a-cc863e417fcc"
/> | <img width="612" height="903" alt="image"
src="https://github.com/user-attachments/assets/a91f5efb-230a-4214-b16b-04278b3ef9ee"
/>|


Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Added Python dunder variables highlighting via `attribute.special` in
themes.
This commit is contained in:
Alex Lachance authored and GitHub committed 2026-08-06 15:29:26 +00:00
1 parent c5abddc286
commit 21ffa9d8ce
1 file changed
+10
+10
View File
@@ -338,6 +338,16 @@
(identifier) @attribute.builtin
(#any-of? @attribute.builtin "classmethod" "staticmethod" "property"))
(attribute
attribute: (identifier) @attribute.special
(#any-of? @attribute.special
"__all__" "__annotations__" "__bases__" "__builtins__" "__class__" "__closure__" "__code__"
"__debug__" "__defaults__" "__dict__" "__doc__" "__file__" "__func__" "__globals__"
"__kwdefaults__" "__match_args__" "__members__" "__metaclass__" "__methods__" "__module__"
"__mro__" "__mro_entries__" "__name__" "__qualname__" "__post_init__" "__self__" "__signature__"
"__slots__" "__subclasses__" "__version__" "__weakref__" "__wrapped__" "__classcell__"
"__spec__" "__path__" "__package__" "__future__" "__traceback__"))
; Builtin types as identifiers
[
(call