Variable: python--treesit-settings
python--treesit-settings is a variable defined in python.el.gz.
Value
Large value
((((comment) @font-lock-comment-face) t comment nil nil python)
(((string) @python--treesit-fontify-string
(interpolation ["{" "}"] @font-lock-misc-punctuation-face))
t string nil nil python)
((["as" "assert" "async" "await" "break" "case" "class" "continue"
"def" "del" "elif" "else" "except" "exec" "finally" "for" "from"
"global" "if" "import" "lambda" "match" "nonlocal" "pass" "print"
"raise" "return" "try" "while" "with" "yield" "and" "in" "is"
"not" "or" "not in" "is not"]
@font-lock-keyword-face
((identifier) @font-lock-keyword-face
(:match "\\`self\\'" @font-lock-keyword-face)))
t keyword nil nil python)
(((function_definition name: (identifier)
@font-lock-function-name-face)
(class_definition name: (identifier) @font-lock-type-face)
(parameters (identifier) @font-lock-variable-name-face)
(parameters
(typed_parameter (identifier) @font-lock-variable-name-face))
(parameters
(default_parameter name: (identifier)
@font-lock-variable-name-face))
(parameters
(typed_default_parameter name: (identifier)
@font-lock-variable-name-face))
(lambda_parameters (identifier) @font-lock-variable-name-face)
(for_in_clause left: (identifier) @font-lock-variable-name-face)
((import_from_statement name:
((dotted_name (identifier)
@font-lock-type-face)))
(:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face))
(import_from_statement name:
((dotted_name (identifier)
@font-lock-variable-name-face))))
t definition nil nil python)
(((call function: (identifier) @font-lock-builtin-face
(:match
"\\(?:^\\(?:__import__\\|a\\(?:bs\\|iter\\|ll\\|n\\(?:ext\\|y\\)\\|scii\\)\\|b\\(?:in\\|reakpoint\\)\\|c\\(?:allable\\|hr\\|lassmethod\\|ompile\\)\\|d\\(?:elattr\\|i\\(?:r\\|vmod\\)\\)\\|e\\(?:numerate\\|val\\|xec\\)\\|f\\(?:ilter\\|ormat\\)\\|g\\(?:etattr\\|lobals\\)\\|h\\(?:as\\(?:attr\\|h\\)\\|e\\(?:lp\\|x\\)\\)\\|i\\(?:d\\|nput\\|s\\(?:instance\\|subclass\\)\\|ter\\)\\|l\\(?:en\\|ocals\\)\\|m\\(?:a[px]\\|in\\)\\|next\\|o\\(?:bject\\|ct\\|pen\\|rd\\)\\|p\\(?:ow\\|r\\(?:int\\|operty\\)\\)\\|r\\(?:e\\(?:pr\\|versed\\)\\|ound\\)\\|s\\(?:etattr\\|lice\\|orted\\|taticmethod\\|u\\(?:m\\|per\\)\\)\\|type\\|vars\\|zip\\)$\\)"
@font-lock-builtin-face))
(attribute attribute: (identifier) @font-lock-builtin-face
(:match
"\\(?:^\\(?:__\\(?:\\(?:a\\(?:ll\\|nnotations\\)\\|bases\\|c\\(?:\\(?:losur\\|od\\)e\\)\\|d\\(?:efaults\\|ict\\|oc\\)\\|firstlineno\\|globals\\|kwdefaults\\|m\\(?:odule\\|ro\\)\\|name\\|package\\|qualname\\|\\(?:static_attribute\\|type_param\\)s\\)__\\)\\)$\\)"
@font-lock-builtin-face)))
t builtin nil nil python)
(((decorator "@" @font-lock-type-face)
(decorator (call function: (identifier) @font-lock-type-face))
(decorator (identifier) @font-lock-type-face)
(decorator [(attribute) (call (attribute))]
@python--treesit-fontify-dotted-decorator))
t decorator nil nil python)
((((call function: (identifier) @font-lock-type-face)
(:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face))
(call function: (identifier) @font-lock-function-call-face)
(call arguments:
(argument_list
(keyword_argument name: (identifier)
@font-lock-property-name-face)))
(call function:
(attribute attribute: (identifier)
@font-lock-function-call-face)))
t function nil nil python)
(([(true) (false) (none)] @font-lock-constant-face
((assignment (identifier) @font-lock-constant-face)
(:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face))
((call arguments:
(argument_list (identifier) @font-lock-constant-face))
(:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face))
((attribute attribute: (identifier) @font-lock-constant-face)
(:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face)))
t constant nil nil python)
(((assignment left: (identifier) @font-lock-variable-name-face)
(assignment left:
(attribute attribute: (identifier)
@font-lock-variable-name-face))
(augmented_assignment left: (identifier)
@font-lock-variable-name-face)
(named_expression name: (identifier) @font-lock-variable-name-face)
(for_statement left: (identifier) @font-lock-variable-name-face)
(pattern_list [(identifier) (list_splat_pattern (identifier))]
@font-lock-variable-name-face)
(tuple_pattern [(identifier) (list_splat_pattern (identifier))]
@font-lock-variable-name-face)
(list_pattern [(identifier) (list_splat_pattern (identifier))]
@font-lock-variable-name-face))
t assignment nil nil python)
((((identifier) @font-lock-type-face
(:match
"\\(?:^\\(?:A\\(?:\\(?:rithmetic\\|ssertion\\|ttribute\\)Error\\)\\|B\\(?:aseException\\(?:Group\\)?\\|lockingIOError\\|rokenPipeError\\|ufferError\\|ytesWarning\\)\\|C\\(?:\\(?:hildProcess\\|onnection\\(?:Aborted\\|Re\\(?:fused\\|set\\)\\)?\\)Error\\)\\|DeprecationWarning\\|E\\(?:OFError\\|n\\(?:codingWarning\\|vironmentError\\)\\|xception\\(?:Group\\)?\\)\\|F\\(?:ile\\(?:\\(?:Exists\\|NotFound\\)Error\\)\\|loatingPointError\\|utureWarning\\)\\|GeneratorExit\\|I\\(?:OError\\|mport\\(?:Error\\|Warning\\)\\|\\(?:n\\(?:de\\(?:ntation\\|x\\)\\|terrupted\\)\\|sADirectory\\)Error\\)\\|Key\\(?:Error\\|boardInterrupt\\)\\|LookupError\\|M\\(?:\\(?:emory\\|oduleNotFound\\)Error\\)\\|N\\(?:\\(?:ame\\|ot\\(?:ADirectory\\|Implemented\\)\\)Error\\)\\|O\\(?:\\(?:S\\|verflow\\)Error\\)\\|P\\(?:e\\(?:ndingDeprecationWarning\\|rmissionError\\)\\|\\(?:rocessLookup\\|ythonFinalization\\)Error\\)\\|R\\(?:e\\(?:cursionError\\|ferenceError\\|sourceWarning\\)\\|untime\\(?:Error\\|Warning\\)\\)\\|S\\(?:top\\(?:\\(?:Async\\)?Iteration\\)\\|y\\(?:ntax\\(?:Error\\|Warning\\)\\|stemE\\(?:rror\\|xit\\)\\)\\)\\|T\\(?:\\(?:ab\\|imeout\\|ype\\)Error\\)\\|U\\(?:n\\(?:boundLocalError\\|icode\\(?:DecodeError\\|E\\(?:\\(?:ncodeE\\)?rror\\)\\|TranslateError\\|Warning\\)\\)\\|serWarning\\)\\|V\\(?:\\(?:MS\\|alue\\)Error\\)\\|W\\(?:arning\\|indowsError\\)\\|ZeroDivisionError\\)$\\)"
@font-lock-type-face))
(type [(identifier) (none)] @font-lock-type-face)
(type (attribute attribute: (identifier) @font-lock-type-face))
(type
(_ !attribute
[[(identifier) (none)] @font-lock-type-face
(attribute attribute: (identifier) @font-lock-type-face)]))
(type
(subscript
(attribute attribute: (identifier) @font-lock-type-face)))
(type (binary_operator) @python--treesit-fontify-union-types)
(class_definition superclasses:
(argument_list
[(identifier) @font-lock-type-face
(attribute attribute: (identifier)
@font-lock-type-face)
(subscript (identifier) @font-lock-type-face)
(subscript
(attribute attribute: (identifier)
@font-lock-type-face))]))
(class_pattern
(dotted_name (identifier) @font-lock-type-face :anchor))
((call function: (identifier) @func-name
(argument_list :anchor (_)
[(identifier) @font-lock-type-face
(attribute attribute: (identifier)
@font-lock-type-face)
(tuple (identifier) @font-lock-type-face)
(tuple
(attribute attribute: (identifier)
@font-lock-type-face))]
(:match
"\\(?:^\\(?:bool\\|bytearray\\|bytes\\|complex\\|dict\\|float\\|frozenset\\|int\\|list\\|memoryview\\|range\\|set\\|str\\|tuple\\|_?[A-Z][0-9A-Z_a-z]+\\)$\\)"
@font-lock-type-face)))
(:match "^is\\(?:instance\\|subclass\\)$" @func-name))
((call function: (identifier) @func-name
(argument_list :anchor (_) (binary_operator)
@python--treesit-fontify-union-types-strict))
(:match "^is\\(?:instance\\|subclass\\)$" @func-name))
((identifier) @font-lock-type-face
(:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face)))
t type nil nil python)
(((escape_sequence) @font-lock-escape-face) t escape-sequence t nil
python)
(([(integer) (float)] @font-lock-number-face) t number nil nil python)
(((attribute attribute: (identifier) @font-lock-property-use-face)
(class_definition body:
(block
(expression_statement
(assignment left: (identifier)
@font-lock-property-use-face)))))
t property nil nil python)
((["-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "&=" "%"
"%=" "^" "^=" "+" "->" "+=" "<" "<<" "<<=" "<=" "<>" "=" ":=" "=="
">" ">=" ">>" ">>=" "|" "|=" "~" "@" "@="]
@font-lock-operator-face)
t operator nil nil python)
((["(" ")" "[" "]" "{" "}"] @font-lock-bracket-face) t bracket nil
nil python)
((["," "." ":" ";" (ellipsis)] @font-lock-delimiter-face) t delimiter
nil nil python)
(((identifier) @python--treesit-fontify-variable) t variable nil nil
python))
Documentation
Tree-sitter font-lock settings.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defvar python--treesit-settings
(treesit-font-lock-rules
:feature 'comment
:language 'python
'((comment) @font-lock-comment-face)
:feature 'string
:language 'python
'((string) @python--treesit-fontify-string
(interpolation ["{" "}"] @font-lock-misc-punctuation-face))
:feature 'keyword
:language 'python
`([,@python--treesit-keywords] @font-lock-keyword-face
((identifier) @font-lock-keyword-face
(:match "\\`self\\'" @font-lock-keyword-face)))
:feature 'definition
:language 'python
'((function_definition
name: (identifier) @font-lock-function-name-face)
(class_definition
name: (identifier) @font-lock-type-face)
(parameters (identifier) @font-lock-variable-name-face)
(parameters (typed_parameter (identifier) @font-lock-variable-name-face))
(parameters (default_parameter name: (identifier) @font-lock-variable-name-face))
(parameters (typed_default_parameter name: (identifier) @font-lock-variable-name-face))
(lambda_parameters (identifier) @font-lock-variable-name-face)
(for_in_clause
left: (identifier) @font-lock-variable-name-face)
((import_from_statement
name: ((dotted_name (identifier) @font-lock-type-face)))
(:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face))
(import_from_statement
name: ((dotted_name (identifier) @font-lock-variable-name-face))))
:feature 'builtin
:language 'python
`((call function: (identifier) @font-lock-builtin-face
(:match ,(rx-to-string
`(seq bol (or ,@python--treesit-builtins) eol))
@font-lock-builtin-face))
(attribute attribute: (identifier) @font-lock-builtin-face
(:match ,(rx-to-string
`(seq bol
(or ,@python--treesit-special-attributes) eol))
@font-lock-builtin-face)))
:feature 'decorator
:language 'python
'((decorator "@" @font-lock-type-face)
(decorator (call function: (identifier) @font-lock-type-face))
(decorator (identifier) @font-lock-type-face)
(decorator [(attribute) (call (attribute))] @python--treesit-fontify-dotted-decorator))
:feature 'function
:language 'python
'(((call function: (identifier) @font-lock-type-face)
(:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face))
(call function: (identifier) @font-lock-function-call-face)
(call arguments: (argument_list (keyword_argument
name: (identifier) @font-lock-property-name-face)))
(call function: (attribute
attribute: (identifier) @font-lock-function-call-face)))
:feature 'constant
:language 'python
'([(true) (false) (none)] @font-lock-constant-face
((assignment (identifier) @font-lock-constant-face)
(:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face))
((call arguments: (argument_list (identifier) @font-lock-constant-face))
(:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face))
((attribute
attribute: (identifier) @font-lock-constant-face)
(:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face)))
:feature 'assignment
:language 'python
`(;; Variable names and LHS.
(assignment left: (identifier)
@font-lock-variable-name-face)
(assignment left: (attribute
attribute: (identifier)
@font-lock-variable-name-face))
(augmented_assignment left: (identifier)
@font-lock-variable-name-face)
(named_expression name: (identifier)
@font-lock-variable-name-face)
(for_statement left: (identifier) @font-lock-variable-name-face)
(pattern_list [(identifier)
(list_splat_pattern (identifier))]
@font-lock-variable-name-face)
(tuple_pattern [(identifier)
(list_splat_pattern (identifier))]
@font-lock-variable-name-face)
(list_pattern [(identifier)
(list_splat_pattern (identifier))]
@font-lock-variable-name-face))
:feature 'type
:language 'python
`(((identifier) @font-lock-type-face
(:match ,(rx-to-string
`(seq bol (or ,@python--treesit-exceptions)
eol))
@font-lock-type-face))
(type [(identifier) (none)] @font-lock-type-face)
(type (attribute attribute: (identifier) @font-lock-type-face))
;; We don't want to highlight a package of the type
;; (e.g. pack.ClassName). So explicitly exclude patterns with
;; attribute, since we handle dotted type name in the previous
;; rule. The following rule handle
;; generic_type/list/tuple/splat_type nodes.
(type (_ !attribute [[(identifier) (none)] @font-lock-type-face
(attribute attribute: (identifier) @font-lock-type-face) ]))
;; collections.abc.Iterator[T] case.
(type (subscript (attribute attribute: (identifier) @font-lock-type-face)))
;; Nested optional type hints, e.g. val: Lvl1 | Lvl2[Lvl3[Lvl4]].
(type (binary_operator) @python--treesit-fontify-union-types)
;;class Type(Base1, Sequence[T]).
(class_definition
superclasses:
(argument_list [(identifier) @font-lock-type-face
(attribute attribute: (identifier) @font-lock-type-face)
(subscript (identifier) @font-lock-type-face)
(subscript (attribute attribute: (identifier) @font-lock-type-face))]))
;; Pattern matching: case [str(), pack0.Type0()]. Take only the
;; last identifier.
(class_pattern (dotted_name (identifier) @font-lock-type-face :anchor))
;; Highlight the second argument as a type in isinstance/issubclass.
((call function: (identifier) @func-name
(argument_list :anchor (_)
[(identifier) @font-lock-type-face
(attribute attribute: (identifier) @font-lock-type-face)
(tuple (identifier) @font-lock-type-face)
(tuple (attribute attribute: (identifier) @font-lock-type-face))]
(:match ,python--treesit-type-regex @font-lock-type-face)))
(:match "^is\\(?:instance\\|subclass\\)$" @func-name))
;; isinstance(t, int|float).
((call function: (identifier) @func-name
(argument_list :anchor (_)
(binary_operator) @python--treesit-fontify-union-types-strict))
(:match "^is\\(?:instance\\|subclass\\)$" @func-name))
((identifier) @font-lock-type-face
(:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face)))
:feature 'escape-sequence
:language 'python
:override t
'((escape_sequence) @font-lock-escape-face)
:feature 'number
:language 'python
'([(integer) (float)] @font-lock-number-face)
:feature 'property
:language 'python
'((attribute
attribute: (identifier) @font-lock-property-use-face)
(class_definition
body: (block
(expression_statement
(assignment left:
(identifier) @font-lock-property-use-face)))))
:feature 'operator
:language 'python
`([,@python--treesit-operators] @font-lock-operator-face)
:feature 'bracket
:language 'python
'(["(" ")" "[" "]" "{" "}"] @font-lock-bracket-face)
:feature 'delimiter
:language 'python
'(["," "." ":" ";" (ellipsis)] @font-lock-delimiter-face)
:feature 'variable
:language 'python
'((identifier) @python--treesit-fontify-variable))
"Tree-sitter font-lock settings.")