There is a collection of nodes used to represent assignments. Eachassignment statement in the source code becomes a singleAssign node in the AST. Thenodes attribute is alist that contains a node for each assignment target. This isnecessary because assignment can be chained, e.g.a = b = 2.EachNode in the list will be one of the following classes:AssAttr,AssList,AssName, orAssTuple.
Each target assignment node will describe the kind of object beingassigned to:AssName for a simple name, e.g.a = 1.AssAttr for an attribute assigned, e.g.a.x = 1.AssList andAssTuple for list and tuple expansionrespectively, e.g.a, b, c = a_tuple.
The target assignment nodes also have aflags attribute thatindicates whether the node is being used for assignment or in a deletestatement. TheAssName is also used to represent a deletestatement, e.g.del x.
When an expression contains several attribute references, anassignment or delete statement will contain only oneAssAttrnode - for the final attribute reference. The other attributereferences will be represented asGetattr nodes in theexpr attribute of theAssAttr instance.
| Python Library Reference |