Slide 21
Slide 21 text
21
© 2019 Pinterest. All rights reserved.
lib2to3
● Concrete syntax tree
● Added in Python 2.6
● Bundled with fixers for porting code to Python 3
○ Example: Except X,T to except X as T
● Preserves formatting information
○ node.prefix
○ node.get_suffix()
● Track if node was changed
>>> node
Leaf(22, '=')
>>> node.get_suffix()
' '
Syntax Trees
ast
● Abstract syntax tree
● Added in Python 2.6
● Good for static code analysis
Python libraries