From 21ffa9d8ce7d84a2fabaa053ecf135dd8dbbd808 Mon Sep 17 00:00:00 2001 From: Alex Lachance Date: Thu, 6 Aug 2026 11:29:26 -0400 Subject: [PATCH] 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 | | :---------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | |image | image| 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. --- crates/grammars/src/python/highlights.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/grammars/src/python/highlights.scm b/crates/grammars/src/python/highlights.scm index 00daf43fbc..7641cef117 100644 --- a/crates/grammars/src/python/highlights.scm +++ b/crates/grammars/src/python/highlights.scm @@ -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