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
评论列表
文章目录