Missing imports in documentation
AN3223 opened this issue · 3 comments
I've just jumped into this so I apologize if I'm missing something here or if there was/is another issue about this (I did try searching).
In "Writing Your First Macro" in the documentation for the latest version, there is this code snippet:
# macro_module.py
from macropy.core.macros import Macros
macros = Macros()
@macros.expr
def expand(tree, **kw):
print(tree)
print(real_repr(tree))
print(unparse(tree))
return tree
When I run it, I get an error for real_repr
not being defined, and when I remove that I get an error for unparse
not being defined. I dug around and think I've found the right functions, and I got it to work with this:
from macropy.core.macros import Macros, real_repr
from macropy.core import unparse
macros = Macros()
@macros.expr
def expand(tree, **kw):
print(tree)
print(real_repr(tree))
print(unparse(tree))
return tree
With the expected output of:
<_ast.BinOp object at 0x000001EB27ABC2B0>
BinOp(Num(1), Add(), Num(2))
(1 + 2)
3
Hello, I am also new to this project. The code example just below what was referenced above:
# macro_module.py
from macropy.core.macros import Macros
macros = Macros()
@macros.expr
def expand(tree, **kw):
return Num(100)
throws an error as Num is not defined.
I fixed the error by importing Num from ast, but I don't know if ast.Num is the same object as what the tutorial is referencing.
It is indeed, thanks @foldsters