| The following table lists each of the :class:`Node` subclasses defined in |
| :mod:`compiler.ast` and each of the public attributes available on their |
| instances. The values of most of the attributes are themselves :class:`Node` |
| instances or sequences of instances. When the value is something other than an |
| instance, the type is noted in the comment. The attributes are listed in the |
| order in which they are returned by :meth:`getChildren` and |
| :meth:`getChildNodes`. |
| |
n | XXX: input{asttable} :XXX |
n | +-----------------------+--------------------+---------------------------------+ |
| | Node type | Attribute | Value | |
| +=======================+====================+=================================+ |
| | :class:`Add` | :attr:`left` | left operand | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | right operand | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`And` | :attr:`nodes` | list of operands | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`AssAttr` | | *attribute as target of | |
| | | | assignment* | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`expr` | expression on the left-hand | |
| | | | side of the dot | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`attrname` | the attribute name, a string | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`flags` | XXX | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`AssList` | :attr:`nodes` | list of list elements being | |
| | | | assigned to | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`AssName` | :attr:`name` | name being assigned to | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`flags` | XXX | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`AssTuple` | :attr:`nodes` | list of tuple elements being | |
| | | | assigned to | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Assert` | :attr:`test` | the expression to be tested | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`fail` | the value of the | |
| | | | :exc:`AssertionError` | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Assign` | :attr:`nodes` | a list of assignment targets, | |
| | | | one per equal sign | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`expr` | the value being assigned | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`AugAssign` | :attr:`node` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`op` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Backquote` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Bitand` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Bitor` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Bitxor` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Break` | | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`CallFunc` | :attr:`node` | expression for the callee | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`args` | a list of arguments | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`star_args` | the extended \*-arg value | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`dstar_args` | the extended \*\*-arg value | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Class` | :attr:`name` | the name of the class, a string | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`bases` | a list of base classes | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`doc` | doc string, a string or | |
| | | | ``None`` | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`code` | the body of the class statement | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Compare` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`ops` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Const` | :attr:`value` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Continue` | | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Decorators` | :attr:`nodes` | List of function decorator | |
| | | | expressions | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Dict` | :attr:`items` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Discard` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Div` | :attr:`left` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Ellipsis` | | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Expression` | :attr:`node` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Exec` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`locals` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`globals` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`FloorDiv` | :attr:`left` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`For` | :attr:`assign` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`list` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`body` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`else_` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`From` | :attr:`modname` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`names` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Function` | :attr:`decorators` | :class:`Decorators` or ``None`` | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`name` | name used in def, a string | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`argnames` | list of argument names, as | |
| | | | strings | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`defaults` | list of default values | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`flags` | xxx | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`doc` | doc string, a string or | |
| | | | ``None`` | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`code` | the body of the function | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`GenExpr` | :attr:`code` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`GenExprFor` | :attr:`assign` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`iter` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`ifs` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`GenExprIf` | :attr:`test` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`GenExprInner` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`quals` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Getattr` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`attrname` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Global` | :attr:`names` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`If` | :attr:`tests` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`else_` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Import` | :attr:`names` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Invert` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Keyword` | :attr:`name` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Lambda` | :attr:`argnames` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`defaults` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`flags` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`code` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`LeftShift` | :attr:`left` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`List` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`ListComp` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`quals` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`ListCompFor` | :attr:`assign` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`list` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`ifs` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`ListCompIf` | :attr:`test` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Mod` | :attr:`left` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Module` | :attr:`doc` | doc string, a string or | |
| | | | ``None`` | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`node` | body of the module, a | |
| | | | :class:`Stmt` | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Mul` | :attr:`left` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Name` | :attr:`name` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Not` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Or` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Pass` | | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Power` | :attr:`left` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Print` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`dest` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Printnl` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`dest` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Raise` | :attr:`expr1` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`expr2` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`expr3` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Return` | :attr:`value` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`RightShift` | :attr:`left` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Slice` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`flags` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`lower` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`upper` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Sliceobj` | :attr:`nodes` | list of statements | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Stmt` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Sub` | :attr:`left` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`right` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Subscript` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`flags` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`subs` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`TryExcept` | :attr:`body` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`handlers` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`else_` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`TryFinally` | :attr:`body` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`final` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Tuple` | :attr:`nodes` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`UnaryAdd` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`UnarySub` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`While` | :attr:`test` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`body` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`else_` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`With` | :attr:`expr` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`vars` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | | :attr:`body` | | |
| +-----------------------+--------------------+---------------------------------+ |
| | :class:`Yield` | :attr:`value` | | |
| +-----------------------+--------------------+---------------------------------+ |
| |
| |
| Assignment nodes |
| ---------------- |
| |
| There is a collection of nodes used to represent assignments. Each assignment |
| statement in the source code becomes a single :class:`Assign` node in the AST. |
| The :attr:`nodes` attribute is a list that contains a node for each assignment |
| target. This is necessary because assignment can be chained, e.g. ``a = b = |