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 = n.n # type: object is_inverse = False if str(n.n).startswith('-'): # Hackish because of complex. value = -n.n is_inverse = True if isinstance(value, int): expr = IntExpr(value) # type: Expression 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_complex_expr(self, node: ComplexExpr) -> Node: return ComplexExpr(node.value)