mirror of
https://github.com/astral-sh/ruff.git
synced 2026-11-21 12:16:15 +08:00
Store child IDs in the arena. Expose borrowed typed nodes, fields and source-order lists through generated accessors. The walkers accept an already classified expression or statement. Resolve child IDs with checked indexing.
744 lines
25 KiB
TOML
744 lines
25 KiB
TOML
# This schema defines Python AST node kinds, typed field accessors, and row constructors.
|
|
#
|
|
# Each [Group.nodes.Name] entry declares a node. Types in a group share a view such
|
|
# as Expr or Stmt. The ungrouped section declares nodes such as Arguments and Keyword.
|
|
#
|
|
# A field type names another node or a scalar value. A trailing ? makes the field
|
|
# optional. A trailing * makes it a list. The arena stores child handles and list
|
|
# intervals. Literal text and numbers live in the arena's corresponding value tables.
|
|
#
|
|
# Fields appear in declaration order unless source_order specifies a different order
|
|
# for traversal. Set is_annotation on an expression field to call the visitor's
|
|
# annotation hook. A node's variant defaults to its name with the group prefix removed.
|
|
# Groups can add a suffix to generated kind checks, as in is_if_stmt.
|
|
|
|
[Mod]
|
|
doc = "See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)"
|
|
|
|
[Mod.nodes.ModModule]
|
|
doc = "See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)"
|
|
fields = [{ name = "body", type = "Stmt*" }]
|
|
|
|
[Mod.nodes.ModExpression]
|
|
doc = "See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)"
|
|
fields = [{ name = "body", type = "Expr" }]
|
|
|
|
[Stmt]
|
|
add_suffix_to_is_methods = true
|
|
doc = "See also [stmt](https://docs.python.org/3/library/ast.html#ast.stmt)"
|
|
|
|
[Stmt.nodes.StmtFunctionDef]
|
|
doc = """See also [FunctionDef](https://docs.python.org/3/library/ast.html#ast.FunctionDef)
|
|
and [AsyncFunctionDef](https://docs.python.org/3/library/ast.html#ast.AsyncFunctionDef).
|
|
|
|
This type differs from the original Python AST, as it collapses the synchronous and asynchronous variants into a single type."""
|
|
fields = [
|
|
{ name = "is_async", type = "bool" },
|
|
{ name = "decorator_list", type = "Decorator*" },
|
|
{ name = "name", type = "Identifier" },
|
|
{ name = "type_params", type = "TypeParams?" },
|
|
{ name = "parameters", type = "Parameters" },
|
|
{ name = "returns", type = "Expr?", is_annotation = true },
|
|
{ name = "body", type = "Stmt*" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtClassDef]
|
|
doc = "See also [ClassDef](https://docs.python.org/3/library/ast.html#ast.ClassDef)"
|
|
fields = [
|
|
{ name = "decorator_list", type = "Decorator*" },
|
|
{ name = "name", type = "Identifier" },
|
|
{ name = "type_params", type = "TypeParams?" },
|
|
{ name = "arguments", type = "Arguments?" },
|
|
{ name = "body", type = "Stmt*" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtReturn]
|
|
doc = "See also [Return](https://docs.python.org/3/library/ast.html#ast.Return)"
|
|
fields = [{ name = "value", type = "Expr?" }]
|
|
|
|
[Stmt.nodes.StmtDelete]
|
|
doc = "See also [Delete](https://docs.python.org/3/library/ast.html#ast.Delete)"
|
|
fields = [{ name = "targets", type = "Expr*" }]
|
|
|
|
[Stmt.nodes.StmtTypeAlias]
|
|
doc = "See also [TypeAlias](https://docs.python.org/3/library/ast.html#ast.TypeAlias)"
|
|
fields = [
|
|
{ name = "name", type = "Expr" },
|
|
{ name = "type_params", type = "TypeParams?" },
|
|
{ name = "value", type = "Expr" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtAssign]
|
|
doc = "See also [Assign](https://docs.python.org/3/library/ast.html#ast.Assign)"
|
|
fields = [
|
|
{ name = "targets", type = "Expr*" },
|
|
{ name = "value", type = "Expr" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtAugAssign]
|
|
doc = "See also [AugAssign](https://docs.python.org/3/library/ast.html#ast.AugAssign)"
|
|
fields = [
|
|
{ name = "target", type = "Expr" },
|
|
{ name = "op", type = "Operator" },
|
|
{ name = "value", type = "Expr" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtAnnAssign]
|
|
doc = "See also [AnnAssign](https://docs.python.org/3/library/ast.html#ast.AnnAssign)"
|
|
fields = [
|
|
{ name = "target", type = "Expr" },
|
|
{ name = "annotation", type = "Expr", is_annotation = true },
|
|
{ name = "value", type = "Expr?" },
|
|
{ name = "simple", type = "bool" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtFor]
|
|
doc = """See also [For](https://docs.python.org/3/library/ast.html#ast.For)
|
|
and [AsyncFor](https://docs.python.org/3/library/ast.html#ast.AsyncFor).
|
|
|
|
This type differs from the original Python AST, as it collapses the synchronous and asynchronous variants into a single type."""
|
|
fields = [
|
|
{ name = "is_async", type = "bool" },
|
|
{ name = "target", type = "Expr" },
|
|
{ name = "iter", type = "Expr" },
|
|
{ name = "body", type = "Stmt*" },
|
|
{ name = "orelse", type = "Stmt*" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtWhile]
|
|
doc = """See also [While](https://docs.python.org/3/library/ast.html#ast.While)
|
|
and [AsyncWhile](https://docs.python.org/3/library/ast.html#ast.AsyncWhile)."""
|
|
fields = [
|
|
{ name = "test", type = "Expr" },
|
|
{ name = "body", type = "Stmt*" },
|
|
{ name = "orelse", type = "Stmt*" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtIf]
|
|
doc = "See also [If](https://docs.python.org/3/library/ast.html#ast.If)"
|
|
fields = [
|
|
|
|
{ name = "test", type = "Expr" },
|
|
{ name = "body", type = "Stmt*" },
|
|
{ name = "elif_else_clauses", type = "ElifElseClause*" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtWith]
|
|
doc = """See also [With](https://docs.python.org/3/library/ast.html#ast.With)
|
|
and [AsyncWith](https://docs.python.org/3/library/ast.html#ast.AsyncWith).
|
|
|
|
This type differs from the original Python AST, as it collapses the synchronous and asynchronous variants into a single type."""
|
|
fields = [
|
|
{ name = "is_async", type = "bool" },
|
|
{ name = "items", type = "WithItem*" },
|
|
{ name = "body", type = "Stmt*" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtMatch]
|
|
doc = "See also [Match](https://docs.python.org/3/library/ast.html#ast.Match)"
|
|
fields = [
|
|
{ name = "subject", type = "Expr" },
|
|
{ name = "cases", type = "MatchCase*" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtRaise]
|
|
doc = "See also [Raise](https://docs.python.org/3/library/ast.html#ast.Raise)"
|
|
fields = [{ name = "exc", type = "Expr?" }, { name = "cause", type = "Expr?" }]
|
|
|
|
[Stmt.nodes.StmtTry]
|
|
doc = """See also [Try](https://docs.python.org/3/library/ast.html#ast.Try)
|
|
and [TryStar](https://docs.python.org/3/library/ast.html#ast.TryStar)"""
|
|
fields = [
|
|
{ name = "body", type = "Stmt*" },
|
|
{ name = "handlers", type = "ExceptHandler*" },
|
|
{ name = "orelse", type = "Stmt*" },
|
|
{ name = "finalbody", type = "Stmt*" },
|
|
{ name = "is_star", type = "bool" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtAssert]
|
|
doc = "See also [Assert](https://docs.python.org/3/library/ast.html#ast.Assert)"
|
|
fields = [{ name = "test", type = "Expr" }, { name = "msg", type = "Expr?" }]
|
|
|
|
[Stmt.nodes.StmtImport]
|
|
doc = "See also [Import](https://docs.python.org/3/library/ast.html#ast.Import)"
|
|
fields = [
|
|
{ name = "names", type = "Alias*" },
|
|
{ name = "is_lazy", type = "bool" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtImportFrom]
|
|
doc = "See also [ImportFrom](https://docs.python.org/3/library/ast.html#ast.ImportFrom)"
|
|
fields = [
|
|
{ name = "module", type = "Identifier?" },
|
|
{ name = "names", type = "Alias*" },
|
|
{ name = "level", type = "u32" },
|
|
{ name = "is_lazy", type = "bool" },
|
|
]
|
|
|
|
[Stmt.nodes.StmtGlobal]
|
|
doc = "See also [Global](https://docs.python.org/3/library/ast.html#ast.Global)"
|
|
fields = [{ name = "names", type = "Identifier*" }]
|
|
|
|
[Stmt.nodes.StmtNonlocal]
|
|
doc = "See also [Nonlocal](https://docs.python.org/3/library/ast.html#ast.Nonlocal)"
|
|
fields = [{ name = "names", type = "Identifier*" }]
|
|
|
|
[Stmt.nodes.StmtExpr]
|
|
doc = "See also [Expr](https://docs.python.org/3/library/ast.html#ast.Expr)"
|
|
fields = [{ name = "value", type = "Expr" }]
|
|
|
|
[Stmt.nodes.StmtPass]
|
|
doc = "See also [Pass](https://docs.python.org/3/library/ast.html#ast.Pass)"
|
|
fields = []
|
|
|
|
[Stmt.nodes.StmtBreak]
|
|
doc = "See also [Break](https://docs.python.org/3/library/ast.html#ast.Break)"
|
|
fields = []
|
|
|
|
[Stmt.nodes.StmtContinue]
|
|
doc = "See also [Continue](https://docs.python.org/3/library/ast.html#ast.Continue)"
|
|
fields = []
|
|
|
|
[Stmt.nodes.StmtIpyEscapeCommand]
|
|
# TODO: remove crate:: prefix from IpyEscapeKind after it's auto generated
|
|
doc = """An AST node used to represent a IPython escape command at the statement level.
|
|
|
|
For example,
|
|
```python
|
|
%matplotlib inline
|
|
```
|
|
|
|
## Terminology
|
|
|
|
Escape commands are special IPython syntax which starts with a token to identify
|
|
the escape kind followed by the command value itself. [Escape kind] are the kind
|
|
of escape commands that are recognized by the token: `%`, `%%`, `!`, `!!`,
|
|
`?`, `??`, `/`, `;`, and `,`.
|
|
|
|
Help command (or Dynamic Object Introspection as it's called) are the escape commands
|
|
of the kind `?` and `??`. For example, `?str.replace`. Help end command are a subset
|
|
of Help command where the token can be at the end of the line i.e., after the value.
|
|
For example, `str.replace?`.
|
|
|
|
Here's where things get tricky. I'll divide the help end command into two types for
|
|
better understanding:
|
|
1. Strict version: The token is _only_ at the end of the line. For example,
|
|
`str.replace?` or `str.replace??`.
|
|
2. Combined version: Along with the `?` or `??` token, which are at the end of the
|
|
line, there are other escape kind tokens that are present at the start as well.
|
|
For example, `%matplotlib?` or `%%timeit?`.
|
|
|
|
Priority comes into picture for the "Combined version" mentioned above. How do
|
|
we determine the escape kind if there are tokens on both side of the value, i.e., which
|
|
token to choose? The Help end command always takes priority over any other token which
|
|
means that if there is `?`/`??` at the end then that is used to determine the kind.
|
|
For example, in `%matplotlib?` the escape kind is determined using the `?` token
|
|
instead of `%` token.
|
|
|
|
## Syntax
|
|
|
|
`<IpyEscapeKind><Command value>`
|
|
|
|
The simplest form is an escape kind token followed by the command value. For example,
|
|
`%matplotlib inline`, `/foo`, `!pwd`, etc.
|
|
|
|
`<Command value><IpyEscapeKind ("?" or "??")>`
|
|
|
|
The help end escape command would be the reverse of the above syntax. Here, the
|
|
escape kind token can only be either `?` or `??` and it is at the end of the line.
|
|
For example, `str.replace?`, `math.pi??`, etc.
|
|
|
|
`<IpyEscapeKind><Command value><EscapeKind ("?" or "??")>`
|
|
|
|
The final syntax is the combined version of the above two. For example, `%matplotlib?`,
|
|
`%%timeit??`, etc.
|
|
|
|
[Escape kind]: crate::IpyEscapeKind
|
|
"""
|
|
fields = [
|
|
{ name = "kind", type = "IpyEscapeKind" },
|
|
{ name = "value", type = "str" },
|
|
]
|
|
|
|
[Expr]
|
|
add_suffix_to_is_methods = true
|
|
doc = "See also [expr](https://docs.python.org/3/library/ast.html#ast.expr)"
|
|
|
|
[Expr.nodes.ExprBoolOp]
|
|
doc = "See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp)"
|
|
fields = [{ name = "op", type = "BoolOp" }, { name = "values", type = "Expr*" }]
|
|
|
|
[Expr.nodes.ExprNamed]
|
|
doc = "See also [NamedExpr](https://docs.python.org/3/library/ast.html#ast.NamedExpr)"
|
|
fields = [{ name = "target", type = "Expr" }, { name = "value", type = "Expr" }]
|
|
|
|
[Expr.nodes.ExprBinOp]
|
|
doc = "See also [BinOp](https://docs.python.org/3/library/ast.html#ast.BinOp)"
|
|
fields = [
|
|
{ name = "left", type = "Expr" },
|
|
{ name = "op", type = "Operator" },
|
|
{ name = "right", type = "Expr" },
|
|
]
|
|
|
|
[Expr.nodes.ExprUnaryOp]
|
|
doc = "See also [UnaryOp](https://docs.python.org/3/library/ast.html#ast.UnaryOp)"
|
|
fields = [
|
|
{ name = "op", type = "UnaryOp" },
|
|
{ name = "operand", type = "Expr" },
|
|
]
|
|
|
|
[Expr.nodes.ExprLambda]
|
|
doc = "See also [Lambda](https://docs.python.org/3/library/ast.html#ast.Lambda)"
|
|
fields = [
|
|
{ name = "parameters", type = "Parameters?" },
|
|
{ name = "body", type = "Expr" },
|
|
]
|
|
|
|
[Expr.nodes.ExprIf]
|
|
doc = "See also [IfExp](https://docs.python.org/3/library/ast.html#ast.IfExp)"
|
|
fields = [
|
|
{ name = "test", type = "Expr" },
|
|
{ name = "body", type = "Expr" },
|
|
{ name = "orelse", type = "Expr" },
|
|
]
|
|
source_order = ["body", "test", "orelse"]
|
|
|
|
[Expr.nodes.ExprDict]
|
|
doc = "See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict)"
|
|
fields = [{ name = "items", type = "DictItem*" }]
|
|
|
|
[Expr.nodes.ExprSet]
|
|
doc = "See also [Set](https://docs.python.org/3/library/ast.html#ast.Set)"
|
|
fields = [{ name = "elts", type = "Expr*" }]
|
|
|
|
[Expr.nodes.ExprListComp]
|
|
doc = "See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp)"
|
|
fields = [
|
|
{ name = "elt", type = "Expr" },
|
|
{ name = "generators", type = "Comprehension*" },
|
|
]
|
|
|
|
[Expr.nodes.ExprSetComp]
|
|
doc = "See also [SetComp](https://docs.python.org/3/library/ast.html#ast.SetComp)"
|
|
fields = [
|
|
{ name = "elt", type = "Expr" },
|
|
{ name = "generators", type = "Comprehension*" },
|
|
]
|
|
|
|
[Expr.nodes.ExprDictComp]
|
|
doc = "See also [DictComp](https://docs.python.org/3/library/ast.html#ast.DictComp)"
|
|
fields = [
|
|
{ name = "key", type = "Expr?" },
|
|
{ name = "value", type = "Expr" },
|
|
{ name = "generators", type = "Comprehension*" },
|
|
]
|
|
|
|
[Expr.nodes.ExprGenerator]
|
|
doc = "See also [GeneratorExp](https://docs.python.org/3/library/ast.html#ast.GeneratorExp)"
|
|
fields = [
|
|
{ name = "elt", type = "Expr" },
|
|
{ name = "generators", type = "Comprehension*" },
|
|
{ name = "parenthesized", type = "bool" },
|
|
]
|
|
|
|
[Expr.nodes.ExprAwait]
|
|
doc = "See also [Await](https://docs.python.org/3/library/ast.html#ast.Await)"
|
|
fields = [{ name = "value", type = "Expr" }]
|
|
|
|
[Expr.nodes.ExprYield]
|
|
doc = "See also [Yield](https://docs.python.org/3/library/ast.html#ast.Yield)"
|
|
fields = [{ name = "value", type = "Expr?" }]
|
|
|
|
[Expr.nodes.ExprYieldFrom]
|
|
doc = "See also [YieldFrom](https://docs.python.org/3/library/ast.html#ast.YieldFrom)"
|
|
fields = [{ name = "value", type = "Expr" }]
|
|
|
|
[Expr.nodes.ExprCompare]
|
|
doc = """A comparison or chain of comparisons.
|
|
|
|
`operands` contains all operands in source order, including the leftmost operand.
|
|
For example, `a < b <= c` has operands `[a, b, c]` and operators `[Lt, LtE]`.
|
|
There is at least one operator, and `operands.len() == ops.len() + 1`.
|
|
|
|
See also [Compare](https://docs.python.org/3/library/ast.html#ast.Compare)."""
|
|
fields = [
|
|
{ name = "ops", type = "CmpOp*" },
|
|
{ name = "operands", type = "Expr*" },
|
|
]
|
|
# The fields must be visited simultaneously
|
|
|
|
[Expr.nodes.ExprCall]
|
|
doc = """A call expression whose end offset is derived from its arguments.
|
|
|
|
The parser and error-recovery code must ensure that the call and its arguments
|
|
end at the same offset.
|
|
|
|
See also [Call](https://docs.python.org/3/library/ast.html#ast.Call)"""
|
|
fields = [
|
|
{ name = "func", type = "Expr" },
|
|
{ name = "arguments", type = "Arguments" },
|
|
]
|
|
|
|
[Expr.nodes.ExprFString]
|
|
doc = """An AST node that represents either a single-part f-string literal
|
|
or an implicitly concatenated f-string literal.
|
|
|
|
This type differs from the original Python AST `JoinedStr` in that it
|
|
doesn't join the implicitly concatenated parts into a single string. Instead,
|
|
it keeps them separate and provide various methods to access the parts.
|
|
|
|
See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr)"""
|
|
fields = [{ name = "value", type = "FStringValue" }]
|
|
|
|
[Expr.nodes.ExprTString]
|
|
doc = """An AST node that represents either a single-part t-string literal
|
|
or an implicitly concatenated t-string literal.
|
|
|
|
This type differs from the original Python AST `TemplateStr` in that it
|
|
doesn't join the implicitly concatenated parts into a single string. Instead,
|
|
it keeps them separate and provide various methods to access the parts.
|
|
|
|
See also [TemplateStr](https://docs.python.org/3/library/ast.html#ast.TemplateStr)"""
|
|
fields = [{ name = "value", type = "TStringValue" }]
|
|
|
|
[Expr.nodes.ExprStringLiteral]
|
|
doc = """An AST node that represents either a single-part string literal
|
|
or an implicitly concatenated string literal."""
|
|
fields = [{ name = "value", type = "StringValue" }]
|
|
# Because StringLiteralValue type is an iterator and it's not clear from the type
|
|
|
|
[Expr.nodes.ExprBytesLiteral]
|
|
doc = """An AST node that represents either a single-part bytestring literal
|
|
or an implicitly concatenated bytestring literal."""
|
|
fields = [{ name = "value", type = "BytesValue" }]
|
|
# Because BytesLiteralValue type is an iterator and it's not clear from the type
|
|
|
|
[Expr.nodes.ExprNumberLiteral]
|
|
fields = [{ name = "value", type = "Number" }]
|
|
|
|
[Expr.nodes.ExprBooleanLiteral]
|
|
fields = [{ name = "value", type = "bool" }]
|
|
|
|
[Expr.nodes.ExprNoneLiteral]
|
|
fields = []
|
|
|
|
[Expr.nodes.ExprEllipsisLiteral]
|
|
fields = []
|
|
|
|
[Expr.nodes.ExprAttribute]
|
|
doc = "See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute)"
|
|
fields = [
|
|
{ name = "value", type = "Expr" },
|
|
{ name = "attr", type = "Identifier" },
|
|
{ name = "ctx", type = "ExprContext" },
|
|
]
|
|
|
|
[Expr.nodes.ExprSubscript]
|
|
doc = "See also [Subscript](https://docs.python.org/3/library/ast.html#ast.Subscript)"
|
|
fields = [
|
|
{ name = "value", type = "Expr" },
|
|
{ name = "slice", type = "Expr" },
|
|
{ name = "ctx", type = "ExprContext" },
|
|
]
|
|
|
|
[Expr.nodes.ExprStarred]
|
|
doc = "See also [Starred](https://docs.python.org/3/library/ast.html#ast.Starred)"
|
|
fields = [
|
|
{ name = "value", type = "Expr" },
|
|
{ name = "ctx", type = "ExprContext" },
|
|
]
|
|
|
|
[Expr.nodes.ExprName]
|
|
doc = "See also [Name](https://docs.python.org/3/library/ast.html#ast.Name)"
|
|
fields = [
|
|
{ name = "id", type = "Name" },
|
|
{ name = "ctx", type = "ExprContext" },
|
|
]
|
|
|
|
[Expr.nodes.ExprList]
|
|
doc = "See also [List](https://docs.python.org/3/library/ast.html#ast.List)"
|
|
fields = [
|
|
{ name = "elts", type = "Expr*" },
|
|
{ name = "ctx", type = "ExprContext" },
|
|
]
|
|
|
|
[Expr.nodes.ExprTuple]
|
|
doc = "See also [Tuple](https://docs.python.org/3/library/ast.html#ast.Tuple)"
|
|
fields = [
|
|
{ name = "elts", type = "Expr*" },
|
|
{ name = "ctx", type = "ExprContext" },
|
|
{ name = "parenthesized", type = "bool" },
|
|
]
|
|
|
|
[Expr.nodes.ExprSlice]
|
|
doc = "See also [Slice](https://docs.python.org/3/library/ast.html#ast.Slice)"
|
|
fields = [
|
|
{ name = "lower", type = "Expr?" },
|
|
{ name = "upper", type = "Expr?" },
|
|
{ name = "step", type = "Expr?" },
|
|
]
|
|
|
|
[Expr.nodes.ExprIpyEscapeCommand]
|
|
doc = """An AST node used to represent a IPython escape command at the expression level.
|
|
|
|
For example,
|
|
```python
|
|
dir = !pwd
|
|
```
|
|
|
|
Here, the escape kind can only be `!` or `%` otherwise it is a syntax error.
|
|
|
|
For more information related to terminology and syntax of escape commands,
|
|
see [`StmtIpyEscapeCommand`]."""
|
|
|
|
fields = [
|
|
{ name = "kind", type = "IpyEscapeKind" },
|
|
{ name = "value", type = "str" },
|
|
]
|
|
|
|
[ExceptHandler]
|
|
doc = "See also [excepthandler](https://docs.python.org/3/library/ast.html#ast.excepthandler)"
|
|
|
|
[ExceptHandler.nodes.ExceptHandlerExceptHandler]
|
|
doc = "See also [ExceptHandler](https://docs.python.org/3/library/ast.html#ast.ExceptHandler)"
|
|
fields = [
|
|
{ name = "type_", type = "Expr?" },
|
|
{ name = "name", type = "Identifier?" },
|
|
{ name = "body", type = "Stmt*" },
|
|
]
|
|
|
|
[InterpolatedStringElement.nodes.InterpolatedElement]
|
|
doc = "See also [FormattedValue](https://docs.python.org/3/library/ast.html#ast.FormattedValue)"
|
|
variant = "Interpolation"
|
|
fields = [
|
|
{ name = "expression", type = "Expr" },
|
|
{ name = "debug_text", type = "DebugText?" },
|
|
{ name = "conversion", type = "ConversionFlag" },
|
|
{ name = "format_spec", type = "InterpolatedStringFormatSpec?" },
|
|
]
|
|
|
|
[InterpolatedStringElement.nodes.InterpolatedStringLiteralElement]
|
|
doc = "An `FStringLiteralElement` with an empty `value` is an invalid f-string element."
|
|
variant = "Literal"
|
|
fields = [
|
|
{ name = "value", type = "LiteralText" },
|
|
]
|
|
|
|
[Pattern]
|
|
doc = "See also [pattern](https://docs.python.org/3/library/ast.html#ast.pattern)"
|
|
|
|
[Pattern.nodes.PatternMatchValue]
|
|
doc = "See also [MatchValue](https://docs.python.org/3/library/ast.html#ast.MatchValue)"
|
|
fields = [{ name = "value", type = "Expr" }]
|
|
|
|
[Pattern.nodes.PatternMatchSingleton]
|
|
doc = "See also [MatchSingleton](https://docs.python.org/3/library/ast.html#ast.MatchSingleton)"
|
|
fields = [{ name = "value", type = "Singleton" }]
|
|
|
|
[Pattern.nodes.PatternMatchSequence]
|
|
doc = "See also [MatchSequence](https://docs.python.org/3/library/ast.html#ast.MatchSequence)"
|
|
fields = [{ name = "patterns", type = "Pattern*" }]
|
|
|
|
[Pattern.nodes.PatternMatchMapping]
|
|
doc = "See also [MatchMapping](https://docs.python.org/3/library/ast.html#ast.MatchMapping)"
|
|
fields = [{ name = "items", type = "MappingPatternItems" }]
|
|
|
|
[Pattern.nodes.PatternMatchClass]
|
|
doc = "See also [MatchClass](https://docs.python.org/3/library/ast.html#ast.MatchClass)"
|
|
fields = [
|
|
{ name = "cls", type = "Expr" },
|
|
{ name = "arguments", type = "PatternArguments" },
|
|
]
|
|
|
|
[Pattern.nodes.PatternMatchStar]
|
|
doc = "See also [MatchStar](https://docs.python.org/3/library/ast.html#ast.MatchStar)"
|
|
fields = [{ name = "name", type = "Identifier?" }]
|
|
|
|
[Pattern.nodes.PatternMatchAs]
|
|
doc = "See also [MatchAs](https://docs.python.org/3/library/ast.html#ast.MatchAs)"
|
|
fields = [
|
|
{ name = "pattern", type = "Pattern?" },
|
|
{ name = "name", type = "Identifier?" },
|
|
]
|
|
|
|
[Pattern.nodes.PatternMatchOr]
|
|
doc = "See also [MatchOr](https://docs.python.org/3/library/ast.html#ast.MatchOr)"
|
|
fields = [{ name = "patterns", type = "Pattern*" }]
|
|
|
|
[TypeParam]
|
|
doc = "See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param)"
|
|
|
|
[TypeParam.nodes.TypeParamTypeVar]
|
|
doc = "See also [TypeVar](https://docs.python.org/3/library/ast.html#ast.TypeVar)"
|
|
fields = [
|
|
{ name = "name", type = "Identifier" },
|
|
{ name = "bound", type = "Expr?" },
|
|
{ name = "default", type = "Expr?" },
|
|
]
|
|
|
|
[TypeParam.nodes.TypeParamTypeVarTuple]
|
|
doc = "See also [TypeVarTuple](https://docs.python.org/3/library/ast.html#ast.TypeVarTuple)"
|
|
fields = [
|
|
{ name = "name", type = "Identifier" },
|
|
{ name = "default", type = "Expr?" },
|
|
]
|
|
|
|
[TypeParam.nodes.TypeParamParamSpec]
|
|
doc = "See also [ParamSpec](https://docs.python.org/3/library/ast.html#ast.ParamSpec)"
|
|
fields = [
|
|
{ name = "name", type = "Identifier" },
|
|
{ name = "default", type = "Expr?" },
|
|
]
|
|
|
|
[ungrouped.nodes.InterpolatedStringFormatSpec]
|
|
fields = [
|
|
{ name = "elements", type = "InterpolatedStringElement*" },
|
|
]
|
|
|
|
[ungrouped.nodes.PatternArguments]
|
|
doc = "The parenthesized arguments of a class pattern, as in `case Point(1, x=0, y=0)`."
|
|
fields = [{ name = "items", type = "PatternArgumentId*" }]
|
|
|
|
[ungrouped.nodes.PatternKeyword]
|
|
doc = """
|
|
An AST node to represent the keyword arguments to a [`crate::PatternMatchClass`], i.e., the
|
|
`x=0` and `y=0` in `case Point(x=0, y=0)`.
|
|
|
|
Like [`Keyword`], but for [`crate::PatternMatchClass`].
|
|
"""
|
|
fields = [
|
|
{ name = "attr", type = "Identifier" },
|
|
{ name = "pattern", type = "Pattern" },
|
|
]
|
|
|
|
[ungrouped.nodes.Comprehension]
|
|
doc = "See also [comprehension](https://docs.python.org/3/library/ast.html#ast.comprehension)"
|
|
fields = [
|
|
{ name = "target", type = "Expr" },
|
|
{ name = "iter", type = "Expr" },
|
|
{ name = "ifs", type = "Expr*" },
|
|
{ name = "is_async", type = "bool" },
|
|
]
|
|
|
|
[ungrouped.nodes.Arguments]
|
|
fields = [{ name = "items", type = "ArgumentId*" }]
|
|
|
|
[ungrouped.nodes.Parameters]
|
|
fields = [{ name = "items", type = "ParameterItems" }]
|
|
|
|
[ungrouped.nodes.Parameter]
|
|
doc = "See also [arg](https://docs.python.org/3/library/ast.html#ast.arg)"
|
|
fields = [
|
|
{ name = "name", type = "Identifier" },
|
|
{ name = "annotation", type = "Expr?", is_annotation = true },
|
|
]
|
|
|
|
[ungrouped.nodes.ParameterWithDefault]
|
|
doc = "A positional or keyword-only parameter and its optional default value. Variadic parameters use [`Parameter`] directly."
|
|
fields = [
|
|
{ name = "parameter", type = "Parameter" },
|
|
{ name = "default", type = "Expr?" },
|
|
]
|
|
|
|
[ungrouped.nodes.DictItem]
|
|
doc = "A dictionary display entry. A missing key represents `**mapping`."
|
|
fields = [
|
|
{ name = "key", type = "Expr?" },
|
|
{ name = "value", type = "Expr" },
|
|
]
|
|
|
|
[ungrouped.nodes.Keyword]
|
|
doc = "See also [keyword](https://docs.python.org/3/library/ast.html#ast.keyword)"
|
|
fields = [
|
|
{ name = "arg", type = "Identifier?" },
|
|
{ name = "value", type = "Expr" },
|
|
]
|
|
|
|
[ungrouped.nodes.Alias]
|
|
doc = "See also [alias](https://docs.python.org/3/library/ast.html#ast.alias)"
|
|
fields = [
|
|
{ name = "name", type = "Identifier" },
|
|
{ name = "asname", type = "Identifier?" },
|
|
]
|
|
|
|
[ungrouped.nodes.WithItem]
|
|
doc = "See also [withitem](https://docs.python.org/3/library/ast.html#ast.withitem)"
|
|
fields = [
|
|
{ name = "context_expr", type = "Expr" },
|
|
{ name = "optional_vars", type = "Expr?" },
|
|
]
|
|
|
|
[ungrouped.nodes.MatchCase]
|
|
doc = "See also [match_case](https://docs.python.org/3/library/ast.html#ast.match_case)"
|
|
fields = [
|
|
{ name = "pattern", type = "Pattern" },
|
|
{ name = "guard", type = "Expr?" },
|
|
{ name = "body", type = "Stmt*" },
|
|
]
|
|
|
|
[ungrouped.nodes.Decorator]
|
|
doc = "See also [decorator](https://docs.python.org/3/library/ast.html#ast.decorator)"
|
|
fields = [
|
|
{ name = "expression", type = "Expr" },
|
|
]
|
|
|
|
[ungrouped.nodes.ElifElseClause]
|
|
fields = [
|
|
{ name = "test", type = "Expr?" },
|
|
{ name = "body", type = "Stmt*" },
|
|
]
|
|
|
|
[ungrouped.nodes.TypeParams]
|
|
fields = [
|
|
{ name = "type_params", type = "TypeParam*" },
|
|
]
|
|
|
|
[ungrouped.nodes.FString]
|
|
doc = "An AST node that represents a single f-string which is part of an [`ExprFString`]."
|
|
fields = [
|
|
{ name = "elements", type = "InterpolatedStringElement*" },
|
|
{ name = "flags", type = "FStringFlags" },
|
|
]
|
|
|
|
[ungrouped.nodes.TString]
|
|
doc = "An AST node that represents a single t-string which is part of an [`ExprTString`]."
|
|
fields = [
|
|
{ name = "elements", type = "InterpolatedStringElement*" },
|
|
{ name = "flags", type = "TStringFlags" },
|
|
]
|
|
|
|
[ungrouped.nodes.StringLiteral]
|
|
doc = """
|
|
An AST node that represents a single string literal which is part of an
|
|
[`ExprStringLiteral`].
|
|
"""
|
|
fields = [
|
|
{ name = "value", type = "LiteralText" },
|
|
{ name = "flags", type = "StringLiteralFlags" },
|
|
]
|
|
|
|
[ungrouped.nodes.BytesLiteral]
|
|
doc = """
|
|
An AST node that represents a single bytes literal which is part of an
|
|
[`ExprBytesLiteral`].
|
|
"""
|
|
fields = [
|
|
{ name = "value", type = "LiteralBytes" },
|
|
{ name = "flags", type = "BytesLiteralFlags" },
|
|
]
|
|
|
|
[ungrouped.nodes.Identifier]
|
|
doc = """
|
|
Parser recovery represents an invalid name with an empty `id`. For example,
|
|
the function name in the following definition has an empty identifier.
|
|
|
|
```python
|
|
def 1():
|
|
...
|
|
```
|
|
"""
|
|
fields = [
|
|
{ name = "id", type = "Name" },
|
|
]
|