From: Frank W. <fwi...@gm...> - 2006-06-27 00:00:28
|
> > I fixed PyComplex and __builtin__ to pass the 2.3 tests but now with the > > latest updates to PyComplex in SVN [2826] another test broke. > > > > The guilty change is this > > > > public PyComplex __complex__() { > > - return this; > > + return new PyComplex(real, imag); > > } > > > > and that breaks this assertion: > > > > complex(c) is c > > To add a little detail to Samuele's explanation: we can't return "this" anymore, because subtypes will call the same __complex__ method but must return a complex and *not* a subtype of complex (which "this" would pass back). PyString goes through the necessary contortions to get this right (among other things like PyUnicode.) see the method returnString in PyString, which was factored out of str_new. in PyComplex it would look something like this: private static PyComplex returnComplex(PyObject S) { if (S instanceof PyComplexDerived) { return new PyComplex(S.getReal(), S.getImag()); }else if (S instanceof PyComplex) { return (PyComplex)S; } //Not sure if there are other possibilities } -Frank |