Add proper tests for astcompile - #651
Merged
Merged
Conversation
- Add AST_FORMAT option to SPyBackend with "short" (default) and "full" modes
- In "full" mode, show lowered node types: LocalDirect(x), OuterCell(x),
AssignLocal(x := val), etc.
- Change NameError formatting to show "raise NameError('name')"
- Add test_astcompile.py with tests for:
- NameError lowering
- for loop desugaring to while
- Name resolution (LocalDirect, ImportRef, OuterCell, OuterDirect)
- Assignment lowering (AssignLocal, AssignCell)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When enabled, shows full AST node types in output (e.g., LocalDirect(x), OuterCell(x), AssignLocal(x := val)). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should have belonged to #649 , but too late and too bad.
The hard part is how to write readable tests, because comparing the generated AST is a pain. We ideally want to use the SPy backend to generated "astcompiled source code", but then all the nuances of NameLocalDirect, AssignLocal, etc, disappears.
The solution was to introduce a new option for the SPy backend
ast_format="full", which annotates some selected nodes with extra info needed for tests.This is now exposed also from the
spycli.E.g.:
with the default "human-readable" format, we don't see any difference:
But with
--full-ast, we do!