New submission from Blair <[EMAIL PROTECTED]>: The following is quoted from the Python docs (ref/numeric_types):
"Note: If the right operand's type is a subclass of the left operand's type and that subclass provides the reflected method for the operation, this method will be called before the left operand's non-reflected method. This behavior allows subclasses to override their ancestors' operations." My issue is that the built-in complex type does not respect this rule (see code below). Note that float can be subclassed using the method shown below and the rules are applied correctly. It seems that it is only a problem with complex. class xcomplex( complex ): def __new__(cls,*args,**kwargs): return complex.__new__(cls,*args,**kwargs) def __coerce__(self,other): t = complex.__coerce__(self,other) try: return (self,xcomplex(t[1])) except TypeError: return t def __add__(self,x): return xcomplex( complex.__add__(self,x) ) def __radd__(self,x): return xcomplex( complex.__radd__(self,x) ) print type(z + xz) # gives complex when xcomplex is required ---------- components: None messages: 72169 nosy: gumtree severity: normal status: open title: subclassing complex type: behavior versions: Python 2.5 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3734> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com