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 Eric Wieser
Recipients Eric Wieser, eric.smith, ezio.melotti, mark.dickinson, mjacob, skrah
Date 2020-08-05.12:03:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1596628982.47.0.783430254061.issue17336@roundup.psfhosted.org>
In-reply-to
Content
> BTW I don't want repr() of a complex number to use the complex(..., ...)

A compromise would be to only use this notation if signed zeros are involved.

---

Another option would be to use slightly unusual reprs for these complex numbers, which at least round-trip:

    def check(s, v):
        c = eval(s)
        # use string equality, because it's the easiest way to compare signed zeros
        cs = f"complex({c.real}, {c.imag})"
        vs = f"complex({v.real}, {v.imag})"
        assert vs == cs, f' expected {vs} got {cs}'

    check("-(0+0j)", complex(-0.0, -0.0))
    check("(-0.0-0j)", complex(-0.0, 0.0))  # non-intuitive
    check("-(-0.0-0j)", complex(0.0, -0.0))  # non-intuitive

Which I suppose would extend to complex numbers containing just one signed zero

    check("(-0.0-1j)", complex(-0.0, -1))
    check("-(0.0-1j)", complex(-0.0, 1))
    check("-(1+0j)", complex(-1, -0.0))
    check("-(-1+0j)", complex(1, -0.0))

Only two of these reprs are misleading for users who don't understand what's going on, the rest will just strike users as odd.
History
Date User Action Args
2020-08-05 12:03:02Eric Wiesersetrecipients: + Eric Wieser, mark.dickinson, eric.smith, ezio.melotti, skrah, mjacob
2020-08-05 12:03:02Eric Wiesersetmessageid: <1596628982.47.0.783430254061.issue17336@roundup.psfhosted.org>
2020-08-05 12:03:02Eric Wieserlinkissue17336 messages
2020-08-05 12:03:02Eric Wiesercreate