Skip to content

Python: Add yeast node type generator for Python extractor AST - #23213

Open
tausbn wants to merge 1 commit into
mainfrom
tausbn/python-yeast-node-types
Open

tausbn wants to merge 1 commit into
mainfrom
tausbn/python-yeast-node-types

Conversation

@tausbn

@tausbn tausbn commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

This uses master.py -- the file that describes the structure of Python ASTs -- to generate a node-types.yml file that can be used by YEAST. On the rare occasion that this file needs to be regenerated, this can be done by invoking make legacy-ast-types, in the same way that make ast regenerates the QL files for the AST.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The schema misclassifies empty structural nodes as literal leaves, breaking YEAST rules, while omitted base-class fields and a generator command that bypasses Poetry introduce additional correctness and setup failures.

3 open issues
What changed in this PR

This PR adds schema generation for using the Python extractor’s legacy AST with YEAST, drawing on master.py and the runtime AST definitions.

Changes:

  • Adds a schema generator with metadata validation and a --check mode.
  • Commits the generated schema and tests its structure and freshness.
  • Adds and documents the make legacy-ast-types regeneration workflow.
File Description
python/​extractor/​yeast-python/​legacy_ast_types.yml Generated node types, fields, and supertypes.
python/​extractor/​tests/​test_legacy_ast_types_gen.py Tests schema structure and generated-file freshness.
python/​extractor/​semmle/​python/​legacy_ast_types_gen.py Generates and validates the legacy AST schema.
python/​extractor/​Makefile Adds the schema regeneration target.
python/​extractor/​extending-the-parser.md Documents regeneration and metadata overrides.

Review effort: Max

Comment thread python/extractor/Makefile Resolved
@tausbn
tausbn force-pushed the tausbn/python-yeast-node-types branch from 7a345f3 to 8d21719 Compare November 23, 2026 16:55
@tausbn
tausbn requested a max review from Copilot November 23, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The documentation omits the need to restore structural-node empty maps after JSON round-trips, and the generator emits fields outside legacy AST slot order, affecting rule behavior, traversal, and typed dumps.

2 open issues
3 resolved since last review

Review effort: Max

Comment thread shared/yeast/doc/node-types-yaml.md Resolved
This uses `master.py` -- the file that describes the structure of Python
ASTs -- and the internal Python extractor AST classes to generate a
`node-types.yml` file that can be used by YEAST. On the rare occasion
that this file needs to be regenerated, this can be done by invoking
`make legacy-ast-types`, in the same way that `make ast` regenerates the
QL files for the AST.

In the process, we ended up needing to distinguish between AST leaves
that carry values (like identifiers) and ones that are just structural
(like `Break`). In the schema, the latter can now be given an explicit
empty map `{}` as fields. This required a small change to `yeast-schema`
and friends.
@tausbn
tausbn force-pushed the tausbn/python-yeast-node-types branch from 8d21719 to 8a39148 Compare November 24, 2026 12:58
@tausbn
tausbn marked this pull request as ready for review November 24, 2026 15:11
@tausbn
tausbn requested review from a team as code owners November 24, 2026 15:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation no-change-note-required This PR does not need a change note Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants