Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 525 Bytes

MultipleTargetAssignmentTransformation.md

File metadata and controls

32 lines (22 loc) · 525 Bytes

Multiple Target Assignment

Overview

Simplifies Python assignment statement.

Example

Before:

class A:
    pass
a = b = c = A() 

After:

class A:
    pass
a = A()
b = a
c = b

The transformation has invariant id(a) == id(b) == id(c).

Algorithm

  1. Traverse the AST and find the node which represents the assignment statement

  2. Replace this node with the sequence of simple assignments.