astatine
raw JSON → 0.3.3 verified Fri May 01 auth: no python maintenance
A collection of handy helper functions for Python's AST module. Provides utilities to simplify AST manipulation, node comparison, pattern matching, and source code reconstruction. Current version 0.3.3 requires Python >=3.6 and is in maintenance mode with no recent releases since 2023.
pip install astatine Common errors
error AttributeError: module 'astatine' has no attribute 'unparse' ↓
cause Older version of astatine (pre-0.3.0) did not include unparse.
fix
Upgrade to 0.3.3: pip install --upgrade astatine
error TypeError: format_node() got an unexpected keyword argument 'indent' ↓
cause The 'indent' parameter was introduced in 0.2.0; using older version or wrong signature.
fix
Check documentation for correct signature: format_node(node, indent=2).
error ImportError: cannot import name 'walk' from 'astatine' ↓
cause The 'walk' function was added in 0.1.0, but might be missing if installed a very old version.
fix
Install version 0.1.0 or later: pip install 'astatine>=0.1.0'
Warnings
deprecated astatine is in maintenance mode with no active development since 2023. Future Python versions (3.12+) may break compatibility. ↓
fix Consider using Python's built-in ast module when possible, or switch to active alternatives like 'astor' or 'typed_ast'.
gotcha The 'unparse' function does not produce valid Python code for all AST nodes (e.g., f-strings with complex expressions may raise errors). ↓
fix Use ast.unparse (Python 3.9+) for reliable output, or thoroughly test astatine's unparse on your ASTs.
gotcha astatine's 'walk' function may behave differently than ast.walk for some node types (e.g., it can miss certain subtrees). ↓
fix Prefer ast.walk for standard traversal unless you specifically need astatine's behavior.
Imports
- format_node
from astatine import format_node - compare_nodes
from astatine import compare_nodes - walk
from astatine import walk - unparse wrong
from ast import unparsecorrectfrom astatine import unparse
Quickstart
import ast
from astatine import format_node, compare_nodes, unparse
tree = ast.parse('x = 1 + 2')
print(format_node(tree))
# compare nodes
node1 = ast.parse('a + b').body[0].value
node2 = ast.parse('a + b').body[0].value
print(compare_nodes(node1, node2)) # True
# unparse to source
print(unparse(tree))