So what you could do is something like this:
addition = "1 + 1"
multiplication = t"{addition} * 7"
result = eval(multiplication) # result is 14
Instead of inserting addition as an exact string, producing "1 + 1 * 7" which is 8, it would parse as an AST and insert the addition node as a unit, so that you get the intended result. You could also do an alpha conversion if the injected code declares variables to avoid name clashes.It wouldn't let you do true macros, but it would make codegen easier and less error-prone.