Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing imports in documentation #86

Open
AN3223 opened this issue May 27, 2018 · 3 comments
Open

Missing imports in documentation #86

AN3223 opened this issue May 27, 2018 · 3 comments
Assignees

Comments

@AN3223
Copy link

AN3223 commented May 27, 2018

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
@azazel75
Copy link
Collaborator

Hi @AN3223,

good catch, thanks

@azazel75 azazel75 self-assigned this May 27, 2018
@foldsters
Copy link

foldsters commented Sep 30, 2018

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.

@azazel75
Copy link
Collaborator

azazel75 commented Oct 4, 2018

It is indeed, thanks @foldsters

azazel75 added a commit to azazel75/macropy that referenced this issue Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants