def test_block_autofix():
# This transformer removes If nodes from statement blocks,
# but it has no way to check whether the resulting body still has some nodes or not.
# That's why the walker adds a Pass node automatically if after all the transformations
# a statement block turns out to be empty.
@ast_transformer
def delete_ifs(node, **kwds):
if isinstance(node, ast.If):
return None
else:
return node
node = get_ast(dummy_if)
new_node = delete_ifs(node)
assert_ast_equal(new_node, get_ast(
"""
def dummy_if():
pass
"""))
评论列表
文章目录