[Python-bugs-list] [ python-Bugs-695651 ] complex_new does not always respect subtypes

SourceForge.net noreply@sourceforge.net
Sun, 02 Mar 2003 06:03:22 -0800


Bugs item #695651, was opened at 2003-03-01 12:18
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=695651&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 6
Submitted By: Greg Chapman (glchapman)
Assigned to: Guido van Rossum (gvanrossum)
Summary: complex_new does not always respect subtypes

Initial Comment:
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)) { 


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2003-03-02 09:03

Message:
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.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-03-02 00:06

Message:
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")?

----------------------------------------------------------------------

Comment By: Greg Chapman (glchapman)
Date: 2003-03-01 12:27

Message:
Logged In: YES 
user_id=86307

Oops, obviously that check should be ;

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

 


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=695651&group_id=5470