This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients docs@python, josh.r, mark.dickinson, rhettinger, rushilu, serhiy.storchaka, steven.daprano, tim.peters
Date 2020-04-13.09:29:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1586770198.85.0.187426247241.issue40269@roundup.psfhosted.org>
In-reply-to
Content
See also #25839, #22548; there's lot of discussion of the core issue on those tickets. As Serhiy says, the only reasonable "true" fix would be to have 1j be a genuine imaginary literal, but that's a lot of work and potential disruption (not just to core Python, but to 3rd party libraries that care about complex numbers) for not a lot of gain.

A documentation improvement as suggested by Raymond sounds good.

I'm not keen on messing with the complex __repr__ again, but if we did, I'd propose not only representing real and imaginary parts in a way that's consistent with floats (so with both real and imaginary parts having either decimal points or exponents), but also showing _both_ the real and imaginary parts in all complex numbers. That is:

    >>> 1j
    0.0 + 1.0j

Or if we're willing to accept more backwards compatibility breakage, there's a case for having the __repr__ (but not the __str__) of a complex number take the form

    >>> 1j
    complex(0.0, 1.0)

since this the only way that allows easy round-tripping. Otherwise you still have this problem:

    >>> complex(-0.0, 1.0)
    (-0+1j)
    >>> -0 + 1j
    1j

BTW, I still dislike the parentheses around the current complex repr.

Let's keep this issue open for potential documentation improvements. If we want to change the repr of complex, let's open another issue for that.
History
Date User Action Args
2020-04-13 09:29:58mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, rhettinger, steven.daprano, docs@python, serhiy.storchaka, josh.r, rushilu
2020-04-13 09:29:58mark.dickinsonsetmessageid: <1586770198.85.0.187426247241.issue40269@roundup.psfhosted.org>
2020-04-13 09:29:58mark.dickinsonlinkissue40269 messages
2020-04-13 09:29:58mark.dickinsoncreate