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

Activity

  1. azazel75 commented on May 27, 2018

    @azazel75
    Collaborator

    Hi @AN3223,

    good catch, thanks

  2. self-assigned this
    on May 27, 2018
  3. foldsters commented on Sep 30, 2018

    @foldsters

    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.

  4. azazel75 commented on Oct 4, 2018

    @azazel75
    Collaborator

    It is indeed, thanks @foldsters

  5. added a commit that references this issue on Oct 4, 2018
    804f8b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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