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

Example code from the readme no longer works #72

Closed
jack-melchert opened this issue Feb 11, 2021 · 2 comments
Closed

Example code from the readme no longer works #72

jack-melchert opened this issue Feb 11, 2021 · 2 comments

Comments

@jack-melchert
Copy link

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.

@leonardt
Copy link
Owner

Here's an example of the latest usage from the test suite:

@apply_passes([loop_unroll()])
def foo():
for i in ast_tools.macros.unroll(range(8)):
print(i)

I believe the latest cst branch merge changed things and we haven't updated the readme yet, apologies

@jack-melchert
Copy link
Author

Perfect! Thanks for the clarification.

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

2 participants