Summary
In this chapter, we have learned about the concept of the abstract syntax tree by exploring the ast
library in Python 3. We also inspected Python code using abstract syntax trees. We understood the applications of abstract syntax trees by modifying the code at the node level using source code from our core example.
Similar to other chapters in this book, this chapter covered the concept of abstract syntax trees in metaprogramming. This also helps in understanding how to modify the behavior of Python objects externally without modifying the source code. Modifying the abstract syntax tree instead of the actual methods and attributes in the code helps migrate source code from different versions of Python or the application development platform conveniently without impacting the actual logic of the code.
In the next chapter, we will be looking at the concept of method resolution order with some other interesting examples.