Skip to content

test: use compile() instead of ast.parse() to catch semantic errors - #169

Merged
boscorat merged 1 commit into
masterfrom
test/compile-check
Aug 6, 2026
Merged

test: use compile() instead of ast.parse() to catch semantic errors#169
boscorat merged 1 commit into
masterfrom
test/compile-check

Conversation

@boscorat

@boscorat boscorat commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

ast.parse() only validates Python grammar — it allows return at module level in the AST. compile() catches semantic errors like return outside function that ast.parse() silently accepts.

This means the previous test (test_module_parses) never actually caught the indentation bug in anonymise.py. Switching to compile() fixes that.

Verification

Before this fix, test_module_compiles[modules/anonymise.py] fails with:

SyntaxError: 'return' outside function (anonymise.py:113)

This correctly blocks merging until #166 restores the indentation.

ast.parse only validates syntax grammar — it allows 'return' at module
level in the AST. compile() catches semantic errors like 'return outside
function' that ast.parse misses.
@boscorat
boscorat merged commit be00c65 into master Aug 6, 2026
3 of 5 checks passed
@boscorat
boscorat deleted the test/compile-check branch August 6, 2026 09:59
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.

1 participant