const_fold.py 文件源码

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

项目:fatoptimizer 作者: vstinner 项目源码 文件源码
def visit_UnaryOp(self, node):
        if not self.config.constant_folding:
            return

        eval_unaryop = EVAL_UNARYOP.get(node.op.__class__)
        if eval_unaryop is None:
            return

        if isinstance(node.op, ast.Invert):
            types = int
        else:
            types =  COMPLEX_TYPES

        value = get_constant(node.operand, types=types)
        if value is not UNSET:
            result = eval_unaryop(value)
            return self.new_constant(node, result)

        if (isinstance(node.op, ast.Not)
        and isinstance(node.operand, ast.Compare)):
            new_node = self.not_compare(node)
            if new_node is not None:
                return new_node
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号