fraction.py 文件源码

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

项目:ml-utils 作者: LinxiFan 项目源码 文件源码
def visit_Num(self, node):
        """
        WARNING: you cannot directly write constants in list. It will throw obscure
        error like "TypeError: required field "lineno" missing from expr"
        You MUST wrap all constants in ast_demo types, like ast_demo.Num(n=42) instead of raw 42
        """
        n = node.n
        if isinstance(n, int):
            new_node = ast.Call(func=ast.Name(id='Fraction', ctx=ast.Load()),
                            args=[node, ast.Num(n=1)], keywords=[])
            ast.copy_location(new_node, node)
            # ast_demo.fix_missing_locations(new_node)
            return new_node
        return node
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号