Skip to content

Missing imports in documentation #86

Description

@AN3223

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions