Skip to content

Example code from the readme no longer works #72

Closed
@jack-melchert

Description

@jack-melchert

While all of the pytest tests pass, the example from the readme:

from ast_tools.passes import begin_rewrite, loop_unroll, end_rewrite

@end_rewrite()
@loop_unroll()
@begin_rewrite()
def foo():
    for i in ast_tools.macros.unroll(range(8)):
        print(i)

Fails with the error:

Traceback (most recent call last):
  File "tests/test_readme.py", line 5, in <module>
    @begin_rewrite()
  File "/ast_tools/ast_tools/passes/base.py", line 23, in __call__
    return self.rewrite(*args)
  File "/ast_tools/ast_tools/passes/loop_unroll.py", line 15, in rewrite
    return unroll_for_loops(tree, env), env, metadata
  File "/ast_tools/ast_tools/transformers/loop_unroller.py", line 49, in unroll_for_loops
    new_body = tree.body.visit(visitor)
AttributeError: 'list' object has no attribute 'visit'

I actually can't get any code that uses either the @begin_rewrite() and @end_rewrite() or the @apply_ast_passes to work.

This is on Python3.7 in a completely new virtualenv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions