PyDocs

Python Language Services

ast

The `ast` module helps Python applications to process trees of the Python
abstract syntax grammar.  The abstract syntax itself might change with
each Python release; this module helps to find out programmatically what
the current grammar looks like and allows modifications of it.

An abstract syntax tree can be generated by passing `ast.PyCF_ONLY_AST` as
a flag to the `compile()` builtin function or by using the `parse()`
function from this module.  The result will be a tree of objects whose
classes all inherit from `ast.AST`.

A modified abstract syntax tree can be compiled into a Python code object
using the built-in `compile()` function.

Additionally various helper functions are provided that make working with
the trees simpler.  The main intention of the helper functions and this
module in general is to provide an easy to use interface for libraries
that work tightly with the python syntax (template engines for example).

:copyright: Copyright 2008 by Armin Ronacher.
:license: Python License.
Symbols in ast

a

Add
Add
alias
alias(identifier name, identifier?
And
And
AnnAssign
AnnAssign(expr target, expr annotation, expr?
arg
arg(identifier arg, expr?
arguments
arguments(arg* posonlyargs, arg* args, arg?
Assert
Assert(expr test, expr?
Assign
Assign(expr* targets, expr value, string?
AST
This is the abstract base of all AST node classes.
AsyncFor
AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string?
AsyncFunctionDef
AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr?
AsyncWith
AsyncWith(withitem* items, stmt* body, string?
Attribute
Attribute(expr value, identifier attr, expr_context ctx)
AugAssign
AugAssign(expr target, operator op, expr value)
Await
Await(expr value)

b

BinOp
BinOp(expr left, operator op, expr right)
BitAnd
BitAnd
BitOr
BitOr
BitXor
BitXor
BoolOp
BoolOp(boolop op, expr* values)
Break
Break

c

Call
Call(expr func, expr* args, keyword* keywords)
ClassDef
ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)
compare
Recursively compares two ASTs.
Compare
Compare(expr left, cmpop* ops, expr* comparators)
comprehension
comprehension(expr target, expr iter, expr* ifs, int is_async)
Constant
Constant(constant value, string?
Continue
Continue
copy_location
Copy source location (`lineno`, `col_offset`, `end_lineno`, and `end_col_offset` attributes) from *old_node* to *new_node* if possible, and return *new_node*.

d

Del
Del
Delete
Delete(expr* targets)
Dict
Dict(expr?* keys, expr* values)
DictComp
DictComp(expr key, expr?
Div
Div
dump
Return a formatted dump of the tree in node.

e

Eq
Eq
ExceptHandler
ExceptHandler(expr?
Expr
Expr(expr value)
Expression
Expression(expr body)

f

fix_missing_locations
When you compile a node tree with compile(), the compiler expects lineno and col_offset attributes for every node that supports them.
FloorDiv
FloorDiv
For
For(expr target, expr iter, stmt* body, stmt* orelse, string?
FormattedValue
FormattedValue(expr value, int conversion, expr?
FunctionDef
FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr?
FunctionType
FunctionType(expr* argtypes, expr returns)

g

GeneratorExp
GeneratorExp(expr elt, comprehension* generators)
get_docstring
Return the docstring for the given node or None if no docstring can be found.
get_source_segment
Get source code segment of the *source* that generated *node*.
Global
Global(identifier* names)
Gt
Gt
GtE
GtE

i

If
If(expr test, stmt* body, stmt* orelse)
IfExp
IfExp(expr test, expr body, expr orelse)
Import
Import(alias* names, int?
ImportFrom
ImportFrom(identifier?
In
In
increment_lineno
Increment the line number and end line number of each node in the tree starting at *node* by *n*.
Interactive
Interactive(stmt* body)
Interpolation
Interpolation(expr value, constant str, int conversion, expr?
Invert
Invert
Is
Is
IsNot
IsNot
iter_child_nodes
Yield all direct child nodes of *node*, that is, all fields that are nodes and all items of fields that are lists of nodes.
iter_fields
Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields`` that is present on *node*.

j

JoinedStr
JoinedStr(expr* values)

k

keyword
keyword(identifier?

l

Lambda
Lambda(arguments args, expr body)
List
List(expr* elts, expr_context ctx)
ListComp
ListComp(expr elt, comprehension* generators)
literal_eval
Evaluate an expression node or a string containing only a Python expression.
Load
Load
LShift
LShift
Lt
Lt
LtE
LtE

m

Match
Match(expr subject, match_case* cases)
match_case
match_case(pattern pattern, expr?
MatchAs
MatchAs(pattern?
MatchClass
MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
MatchMapping
MatchMapping(expr* keys, pattern* patterns, identifier?
MatchOr
MatchOr(pattern* patterns)
MatchSequence
MatchSequence(pattern* patterns)
MatchSingleton
MatchSingleton(constant value)
MatchStar
MatchStar(identifier?
MatchValue
MatchValue(expr value)
MatMult
MatMult
Mod
Mod
Module
Module(stmt* body, type_ignore* type_ignores)
Mult
Mult

n

Name
Name(identifier id, expr_context ctx)
NamedExpr
NamedExpr(expr target, expr value)
NodeTransformer
A :class:`NodeVisitor` subclass that walks the abstract syntax tree and allows modification of nodes.
NodeVisitor
A node visitor base class that walks the abstract syntax tree and calls a visitor function for every node found.
Nonlocal
Nonlocal(identifier* names)
Not
Not
NotEq
NotEq
NotIn
NotIn

o

Or
Or

p

ParamSpec
ParamSpec(identifier name, expr?
parse
Parse the source into an AST node.
Pass
Pass
Pow
Pow
PyCF_ALLOW_TOP_LEVEL_AWAIT
Enables support for top-level await, async for, async with and async comprehensions.
PyCF_ONLY_AST
Generates and returns an abstract syntax tree instead of returning a compiled code object.
PyCF_OPTIMIZED_AST
The returned AST is optimized according to the optimize argument in compile() or ast.parse().
PyCF_TYPE_COMMENTS
Enables support for PEP 484 and PEP 526 style type comments (# type: <type>, # type: ignore <stuff>).

r

Raise
Raise(expr?
Return
Return(expr?
RShift
RShift

s

Set
Set(expr* elts)
SetComp
SetComp(expr elt, comprehension* generators)
Slice
Slice(expr?
Starred
Starred(expr value, expr_context ctx)
Store
Store
Sub
Sub
Subscript
Subscript(expr value, expr slice, expr_context ctx)

t

TemplateStr
TemplateStr(expr* values)
Try
Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
TryStar
TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
Tuple
Tuple(expr* elts, expr_context ctx)
TypeAlias
TypeAlias(expr name, type_param* type_params, expr value)
TypeIgnore
TypeIgnore(int lineno, string tag)
TypeVar
TypeVar(identifier name, expr?
TypeVarTuple
TypeVarTuple(identifier name, expr?

u

UAdd
UAdd
UnaryOp
UnaryOp(unaryop op, expr operand)
unparse
Unparse an ast.AST object and generate a string with code that would produce an equivalent ast.AST object if parsed back with ast.parse().
USub
USub

w

walk
Recursively yield all descendant nodes in the tree starting at *node* (including *node* itself), in no specified order.
While
While(expr test, stmt* body, stmt* orelse)
With
With(withitem* items, stmt* body, string?
withitem
withitem(expr context_expr, expr?

y

Yield
Yield(expr?
YieldFrom
YieldFrom(expr value)