Skip to content

feat:ASTx to pythonAST transpiler implementation with fixes from Identifier Issues#287

Merged
xmnlab merged 4 commits intoarxlang:mainfrom
nagajaideep:main
Aug 29, 2025
Merged

feat:ASTx to pythonAST transpiler implementation with fixes from Identifier Issues#287
xmnlab merged 4 commits intoarxlang:mainfrom
nagajaideep:main

Conversation

@nagajaideep
Copy link
Contributor

Pull Request description

This PR implements mentor-aligned refactoring of the ASTx transpiler architecture to separate AST conversion from string generation, resolving circular dependencies and improving maintainability.

Changes Made:

  • Fixed circular dependency in python_to_ast.py by removing python_string import.
  • Introduced new file python_string.py (new file) to handle ASTx → Python source code generation via ast.unparse().
  • Achieved clean separation of concerns between AST conversion and string output.

This aligns with the mentor’s requested architecture:

ASTx Node → python_to_ast.py (ASTx → Python AST) 
          → python_string_new.py (Python AST → String via ast.unparse())

How to test these changes

Run the new test file:

python -m pytest libs/astx-transpilers/tests/test_python_to_ast.py libs/astx-transpilers/tests/test_python_string.py -v; pre-commit run --all-files

Or manually:

from astx_transpilers.python_to_ast import ASTxPythonASTTranspiler
from astx_transpilers.python_string_new import ASTxPythonTranspiler

# AST output
ast_node = ASTxPythonASTTranspiler().visit(astx_node)

# String output
code_str = ASTxPythonTranspiler().visit(astx_node)

Expected: Correct AST objects and Python source code strings are produced.

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

Benefits of this refactoring:

  1. Single source of truth for ASTx → Python AST (python_to_ast.py)
  2. No circular dependencies
  3. Reusability (AST output usable for multiple backends)
  4. Maintainable and modular design
  5. Uses ast.unparse() for consistent string generation

Reviewer's checklist

## Reviewer's Checklist

- [ ] I managed to reproduce the problem locally from the `main` branch
- [ ] I managed to test the new changes locally
- [ ] 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.

thanks @nagajaideep , lgtm! appreciate it.

@xmnlab xmnlab merged commit 3f91893 into arxlang:main Aug 29, 2025
19 checks passed
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

Successfully merging this pull request may close these issues.

2 participants