Exactly same as in the Annex G. Special rules for imaginary type will apply for complex(0.0, <signed float>)
instances. I did a draft patch in GitHub - skirpichev/cpython at complex-annex-g (only complex_neg/add/sub/mul were changed, no documentation changes, no comments, no optimizations).
With above - the eval(repr)
round-trip problem will be fixed, as well as mentioned in Invalid "equivalents" of the complex type constructor in docs · Issue #109218 · python/cpython · GitHub identities (e.g. z==z.real+z.imag*1j
). No changes in string parsing, only minor changes in the repr output (signed zero used for real component, if needed).
I believe, now this proposal is more precise to be discussed (and, probably, rejected:)). I would appreciate also @storchaka opinion, as this is a some minor modification of the “imaginary type” solution.
Oops. They aren’t exactly equivalent already. Above holds only for non-complex arguments:
>>> complex(a:=-0.0,b:=0j)+complex(c:=-0.0, d:=-0j)
0j
>>> complex(a + c, b + d)
(-0+0j)
And yes, the price will be, as I hope - mentioned special rules for complex(a, b) <op> complex(0.0, c)
, that will actually affect only corner cases (signed zeros, infinities, nans) in components, e.g. complex(-0.0, 1) + complex(0, 1) == complex(-0.0, 2)
.