[issue9011] ast_for_factor unary minus optimization changes AST

Mark Dickinson report at bugs.python.org
Thu Oct 18 14:18:24 CEST 2012


Mark Dickinson added the comment:

With the string, the minus sign applies only to the imaginary part;  with the expression '-1j', it applies to the whole complex number (both real and imaginary parts).

I don't see any sensible way to 'fix' the string to complex conversion; indeed, I think any change would make it worse than before.  It's a known issue with complex arithmetic that x + 1j*y doesn't give you complex(x, y);  the conversions from string and the complex(x, y) form are there to make it possible to carefully create a complex number with known real and imaginary parts.


> For example, in pypy we use the same code for parsing literals and
> converting strings, so you get -0.0 in both cases.

But -1j isn't a literal.  It's unary minus applied to a the complex number given by the literal '1j'.  Python's code *does* give the same results both for converting strings and parsing literals.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9011>
_______________________________________


More information about the Python-bugs-list mailing list