def visit_Num(self, n: ast27.Num) -> Expression: # The n field has the type complex, but complex isn't *really* # a parent of int and float, and this causes isinstance below # to think that the complex branch is always picked. Avoid # this by throwing away the type. value: object = n.n is_inverse = False if str(n.n).startswith('-'): # Hackish because of complex. value = -n.n is_inverse = True if isinstance(value, int): expr: Expression = IntExpr(value) elif isinstance(value, float): expr = FloatExpr(value) elif isinstance(value, complex): expr = ComplexExpr(value) else: raise RuntimeError('num not implemented for ' + str(type(n.n))) if is_inverse: expr = UnaryExpr('-', expr) return self.set_line(expr, n)
def visit_unary_expr(self, node: UnaryExpr) -> Node: new = UnaryExpr(node.op, self.node(node.expr)) new.method_type = self.optional_type(node.method_type) return new