>>> const_value(Local('x')) |
>>> const_value(Local('x')) |
Traceback (most recent call last): |
Traceback (most recent call last): |
... |
... |
NotAConstant: Local('x',) |
NotAConstant: Local('x') |
|
|
Tuples of constants are recursively replaced by constant tuples:: |
Tuples of constants are recursively replaced by constant tuples:: |
|
|
>>> const_value( (1,Global('y')) ) |
>>> const_value( (1,Global('y')) ) |
Traceback (most recent call last): |
Traceback (most recent call last): |
... |
... |
NotAConstant: Global('y',) |
NotAConstant: Global('y') |
|
|
As do any types not previously described here:: |
As do any types not previously described here:: |
|
|
|
|
>>> tf = TryFinally(ExprStmt(1), ExprStmt(2)) |
>>> tf = TryFinally(ExprStmt(1), ExprStmt(2)) |
>>> tf |
>>> tf |
TryFinally(ExprStmt(1,), ExprStmt(2,)) |
TryFinally(ExprStmt(1), ExprStmt(2)) |
|
|
* It makes named fields accessible:: |
* It makes named fields accessible:: |
|
|
>>> tf.block1 |
>>> tf.block1 |
ExprStmt(1,) |
ExprStmt(1) |
|
|
>>> tf.block2 |
>>> tf.block2 |
ExprStmt(2,) |
ExprStmt(2) |
|
|
* Hashing and comparison work as expected (handy for algorithms that require |
* Hashing and comparison work as expected (handy for algorithms that require |
comparing or caching AST subtrees, such as common subexpression |
comparing or caching AST subtrees, such as common subexpression |