Contribute Media
A thank you to everyone who makes this possible: Read More

Python has a macro language: it's Python


Python has a macro language: it’s Python - PyCon Italia 2022

A small but growing number of Python projects, including attrs, cattrs and incant, use Python to generate Python.

We will example concrete cases of code generation in these libraries and go over the ‘how’ and the ‘why’. Macros in mainstream languages are generally a tool for metaprogramming, probably the most famous examples being preprocessor directives in C and C++, and Rust macros.

Python has rich metaprogramming capabilities baked in through the compile and eval built-in functions, although a little care needs to be taken for the generated code to be debuggable and properly shown in track staces.

We will examine one concrete example of metaprogramming in each of the attrs, cattrs and incant libraries.

Speaker: Tin Tvrtkovic


Improve this page