Bogus parsing/eval of complex literals
问题 When evaluating complex numbers, python likes to fiddle the signs. >>> -0j (-0-0j) >>> (-0-0j) 0j Why? nb: I noticed it when reading this question. 回答1: The issue here is that Python doesn't parse complex numbers such as (-0-0j) as literals, they are actually parsed as an expression: >>> import ast >>> ast.dump(ast.parse('(-0-0j)')) 'Module(body=[Expr(value=BinOp(left=UnaryOp(op=USub(), operand=Num(n=0)), op=Sub(), right=Num(n=0j)))])' So, this is not a complex literal but a reflected