astcheck is a Python library designed to check Abstract Syntax Trees (ASTs) against structured templates. It's particularly useful for testing AST transformations, linters, or any code that processes Python ASTs. The current version is 0.4.0, with releases occurring periodically to address minor improvements and Python version compatibility.
pip install astcheckVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse Python code into an AST, define a template AST using `ast.parse` and `astcheck.NAME` placeholders, and then use `is_ast_match` to check for structural similarity. It also shows `assert_ast_equal` for strict comparisons and `match_ast` for extracting matched nodes.
Always use `ast.parse('your_code_string')` to convert your template string into an AST node before passing it to `astcheck` functions.Ensure you `from astcheck import NAME, N_INT, ...` and then pass `some_name=NAME` or use `astcheck.NAME` in your template where appropriate.
If you need to debug why two ASTs are considered different, use `ast.dump(node)` for both the target and template ASTs to visualize their exact structure and identify discrepancies.
No dependency data recorded yet.