Again perhaps the end of [#460020] bug or feature: unicode() and subclasses.
Inhibited complex unary plus optimization when applied to a complex subtype.
Added PyComplex_CheckExact macro. Some comments and minor code fiddling.
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index b029979..f8b7fc7 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1430,6 +1430,30 @@
verify(hash(a) == hash(12345.0))
verify((+a).__class__ is float)
+ class madcomplex(complex):
+ def __repr__(self):
+ return "%.17gj%+.17g" % (self.imag, self.real)
+ a = madcomplex(-3, 4)
+ verify(repr(a) == "4j-3")
+ base = complex(-3, 4)
+ verify(base.__class__ is complex)
+ verify(complex(a) == base)
+ verify(complex(a).__class__ is complex)
+ a = madcomplex(a) # just trying another form of the constructor
+ verify(repr(a) == "4j-3")
+ verify(complex(a) == base)
+ verify(complex(a).__class__ is complex)
+ verify(hash(a) == hash(base))
+ verify((+a).__class__ is complex)
+ verify((a + 0).__class__ is complex)
+ verify(a + 0 == base)
+ verify((a - 0).__class__ is complex)
+ verify(a - 0 == base)
+ verify((a * 1).__class__ is complex)
+ verify(a * 1 == base)
+ verify((a / 1).__class__ is complex)
+ verify(a / 1 == base)
+
class madtuple(tuple):
_rev = None
def rev(self):