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.

classification
Title: complex_new does not always respect subtypes
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: glchapman, gvanrossum, tim.peters
Priority: high Keywords:

Created on 2003-03-01 17:18 by glchapman, last changed 2022-04-10 16:07 by admin. This issue is now closed.

Messages (4)
msg14900 - (view) Author: Greg Chapman (glchapman) Date: 2003-03-01 17:18
On comp.lang.python, David Mertz pointed out this:

>>> class ComplexSub(complex): pass
... 
>>> c = ComplexSub(1+1j)
>>> type(c)
<type 'complex'>

In other words, trying to create a ComplexSub returns a 
complex.  The problem appears to be this check in 
complex_new:

 /* Special-case for single argumet that is already 
complex */ 
           if (PyComplex_CheckExact(r) && i == NULL) { 

I believe the above should also check to see if the type 
parameter is exactly complex:

 /* Special-case for single argumet that is already 
complex */ 
           if (PyComplex_CheckExact(r) && i == NULL && 
PyComplex_CheckExact(type)) { 
msg14901 - (view) Author: Greg Chapman (glchapman) Date: 2003-03-01 17:27
Logged In: YES 
user_id=86307

Oops, obviously that check should be ;

if (PyComplex_CheckExact(r) && i == NULL && 
 type == &PyComplex_Type) {

 
msg14902 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-03-02 05:06
Logged In: YES 
user_id=31435

Bumped priority & assigned to Guido.  Guido, might this be 
related to that your MyComplex class in pickletester.py 
isn't used (you left an XXX comment there just noting that 
it "doesn't work")?
msg14903 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-03-02 14:03
Logged In: YES 
user_id=6380

Bingo! Fixed, and checked in. There was another bug waiting
to happen once I enabled the pickletester.py change;
complex_newargs() contained a segfaulting bug.
History
Date User Action Args
2022-04-10 16:07:15adminsetgithub: 38076
2003-03-01 17:18:52glchapmancreate