test_walker.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:peval 作者: fjarri 项目源码 文件源码
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
        """))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号