inject_assert.py 文件源码

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

项目:ml-utils 作者: LinxiFan 项目源码 文件源码
def visit_Assert(self, node):
        if isinstance(node.test, ast.Compare) and \
                len(node.test.ops) == 1 and \
                isinstance(node.test.ops[0], ast.Eq):
            call = ast.Call(func=ast.Name(id='assert_equal', ctx=ast.Load()),
                            args=[node.test.left, node.test.comparators[0]],
                            keywords=[])
            # Wrap the call in an Expr node, because the return value isn't used.
            newnode = ast.Expr(value=call)
            ast.copy_location(newnode, node)
            ast.fix_missing_locations(newnode)
            return newnode

        # Return the original node if we don't want to change it.
        return node
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号