python / python/cpython

IDLE: add an AST browser

Open
#152,942 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-IDLE type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

As a companion to the proposed token browser (#152941), visualizing the abstract syntax tree helps in learning how Python parses code and in understanding the structure that the compiler works from.

I propose an AST Browser added as an extension on the Tools menu (Shell and editor). It shows ast.parse of the current window as a hierarchical, fully expanded ttk.Treeview, each node labeled with its type and inline simple fields.

Interaction:

  • Selecting a node highlights the corresponding source in the editor.
  • The browser follows the editor: the editor selection (or cursor) selects the single smallest enclosing node.
  • Scope is the editor selection if it parses, else the Shell's current input, else the whole window (a context-dependent fragment that does not parse reports the syntax error).

It shares the window skeleton and editor-sync mechanism with the token browser, so the two are best reviewed and landed together.

A PR will follow.

Linked PRs
  • gh-152947

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the companion token browser issue #152941 and the linked PR gh-152947, since this issue names no implementation files or tests. The work is complete when an IDLE Tools-menu AST Browser parses the applicable source, displays the expanded tree, synchronizes selections with the editor, and reports syntax errors for unparseable fragments.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.