Skip to content

Print AST for debugging purposes #112

Description

@Doomsk

Does anyone know how to get the AST instead of evaluating it directly so one can debug it?

Activity

  1. nobodxbodon commented on Feb 11, 2022

    @nobodxbodon
    Contributor

    I wrote a helper method to walk through the AST and print out the summary in a tree-like format like below:

    Module(
      body=[Assign(
          targets=[Name(
              id='a'
              ctx=Store()
              lineno=1
              col_offset=1
            )]
          value=Num(
            n=2
            lineno=1
            col_offset=3
          )
          lineno=1
          col_offset=1
        )Expr(
          value=Call(
            func=Name(
              id='print'
              ctx=Load()
              lineno=2
              col_offset=1
            )
            args=[Name(
                id='a'
                ctx=Load()
                lineno=2
                col_offset=7
              )]
            keywords=[]
            lineno=2
            col_offset=1
          )
          lineno=2
          col_offset=1
        )]
    )
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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