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, andtuple_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 anexpression_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
nodeis a bare string statement’sstring: 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 theconcatenated_stringnode. - python_
is_ bare_ string_ parenthesis - Whether
nodeis aparenthesized_expressionaround 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_ block - Single normalization point for Python’s aliased
blockkind_ids. - python_
is_ lambda - Whether
nodeis a Pythonlambdaexpression, under either of the grammar’s two aliased kind_ids:Lambda(196, the concrete production emitted today) andLambda2(197, the currently-unseen hidden alias).Lambda3(73) is thelambdakeyword token, not a closure node, and is intentionally excluded. - python_
lambdas_ below_ statement_ boundary - How many
lambdas enclosenodebelow its nearest statement boundary — anexpression_list,if,fororwhile— the countnode.count_specific_ancestors::<PythonCode>(ancestors, python_is_lambda, boundary)takes. - python_
self_ attribute_ name - The attribute name of a
self.<attr>/cls.<attr>attributenode, orNonewhen the receiver is not a self / cls alias — the bytes theMemberrow’s gate and the attribute count both read. - python_
sphinx_ doc_ comment - Credits the rows of a Sphinx doc comment that
commentcompletes (#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, orself.<attr>at the top of__init__).