Skip to main content

Module python

Module python 

Source
Expand description

Python: the aliased block and lambda kind sets, and the shape of a docstring.

Constants§

PYTHON_TARGET_PATTERN_KINDS
The destructuring wrappers an assignment target nests its elements in: pattern_list / expression_list, and tuple_pattern / list_pattern, which each carry two aliased kind ids — the hidden supertype (TuplePattern / ListPattern, never emitted) and the live node the grammar produces for (a, b) = … / [a, b] = … (TuplePattern2 / ListPattern2). Matching only the supertype alias silently dropped every parenthesised / bracketed unpacking target, so both are listed per the hidden-alias discipline (#419).

Functions§

python_documentation_string_run
Credits a consecutive run of documentation strings at its last string. Comments between statements do not break the run. Deciding once keeps additional-docstring recognition linear in the number of statements.
python_is_bare_statement_value
Whether node, past any parentheses around it, is the sole child of an expression_statement: the discarded-value shape a docstring takes. CPython drops the parentheses, so ("""doc""") is a docstring (#1610). "a", "b" has two children, so it is a discarded tuple, not documentation.
python_is_bare_string
Whether node is a bare string statement’s string: the statement’s sole value itself, or one fragment of an implicitly concatenated literal ("""doc""" "more") that is — CPython joins the fragments into one string, and so does the concatenated_string node.
python_is_bare_string_parenthesis
Whether node is a parenthesized_expression around a bare string statement’s string, or one of its ( and ). The parentheses belong to the docstring they wrap (#1610): neither code rows nor operators.
python_is_bare_string_statement
Whether statement is a bare string statement: an expression_statement whose sole value is a string or concatenated_string, past any parentheses around it. Asked of a node alone, with no chain — the LOC walk’s \ finder descends to a statement that is a sibling’s descendant (#1819).
python_is_block
Single normalization point for Python’s aliased block kind_ids.
python_is_extra
Whether node is one of the grammar’s two extras, a # comment or a \ line continuation: the nodes tree-sitter-python admits between any two tokens, which spell no part of the construct they sit in.
python_is_lambda
Whether node is a Python lambda expression, under either of the grammar’s two aliased kind_ids: Lambda (196, the concrete production emitted today) and Lambda2 (197, the currently-unseen hidden alias). Lambda3 (73) is the lambda keyword token, not a closure node, and is intentionally excluded.
python_lambdas_below_statement_boundary
How many lambdas enclose node below its nearest statement boundary — an expression_list, if, for or while — the count node.count_specific_ancestors::<PythonCode>(ancestors, python_is_lambda, boundary) takes.
python_self_attribute_name
The attribute name of a self.<attr> / cls.<attr> attribute node, or None when the receiver is not a self / cls alias — the bytes the Member row’s gate and the attribute count both read.
python_sphinx_doc_comment
Credits the rows of a Sphinx doc comment that comment completes (#1597). Sphinx autodoc reads a comment starting #: as an attribute’s documentation when it sits on the line of an assignment, after the code, or on the consecutive lines directly above one — every one of them #:; a plain # line breaks the block. The assignment must be one an attribute docstring may follow (module or class level, or self.<attr> at the top of __init__).