Skip to content

feat: Add support for AsyncFor #211

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

Merged
merged 2 commits into from
Mar 14, 2025
Merged

Conversation

JoshuaGlaZ
Copy link
Contributor

Pull Request description

This PR adds support for AsyncFor constructs from the issue #196.

How to test these changes

run the below code

$ pytest tests/test_collections.py
$ pytest pytest tests/tools/transpilers/test_python.py
import astx
from astx.tools.transpilers import python as astx2py
from astx.viz import traverse_ast_ascii, graph_to_ascii

transpiler = astx2py.ASTxPythonTranspiler()

block_ = astx.Block()
block_.append(astx.LiteralString("pass"))

var_x = astx.InlineVariableDeclaration(
    "x", type_=astx.Int32(), value=astx.LiteralInt32(-1)
)

var_y = astx.LiteralInt32(5)

asyncfor_expr = astx.AsyncForRangeLoopExpr(
    variable=var_x, start=None, end=var_y, step=None, body=block_
)
asyncfor_expr

generator = astx2py.ASTxPythonTranspiler()
generated_code = generator.visit(asyncfor_expr)
print(generated_code)

dot_graph = traverse_ast_ascii(asyncfor_expr.get_struct(simplified=True))
graph = graph_to_ascii(dot_graph)
print(graph)

Output:

result = ['pass' async for x in range(0, 5, 1)]

asyncfor2
asyncfor1

Pull Request checklists

Note:

This PR is a:

  • bug-fix
  • new feature
  • maintenance

About this PR:

  • it includes tests.
  • the tests are executed on CI.
  • the tests generate log file(s) (path).
  • pre-commit hooks were executed locally.
  • this PR requires a project documentation update.

Author's checklist:

  • I have reviewed the changes and it contains no misspelling.
  • The code is well commented, especially in the parts that contain more
    complexity.
  • New and old tests passed locally.

Additional information

Reviewer's checklist

Copy and paste this template for your review's note:

## Reviewer's Checklist

- [x] I managed to reproduce the problem locally from the `main` branch
- [x] I managed to test the new changes locally
- [x] I confirm that the issues mentioned were fixed/resolved .

Copy link
Contributor

@xmnlab xmnlab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks @JoshuaGlaZ !

@xmnlab xmnlab merged commit e384edc into arxlang:main Mar 14, 2025
14 checks passed
Zehen-249 pushed a commit to Zehen-249/astx that referenced this pull request Mar 16, 2025
Zehen-249 added a commit to Zehen-249/astx that referenced this pull request Mar 16, 2025
- Change ASRKind code for GeneratorExp
- Add support for `YieldFromExpr` (arxlang#206)
- Add support for `AsyncFor` (arxlang#211)
change ASRKind code for GeneratorExp

feat: Add support for `YieldFromExpr` (arxlang#206)

 feat: Add support for `AsyncFor` (arxlang#211)
Copy link

🎉 This PR is included in version 0.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants