[Python-bugs-list] [ python-Bugs-563740 ] complex() doesn't use __complex__

noreply@sourceforge.net noreply@sourceforge.net
Thu, 06 Jun 2002 00:14:47 -0700


Bugs item #563740, was opened at 2002-06-03 00:17
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=563740&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: complex() doesn't use __complex__

Initial Comment:
complex() with a new-style instance of a class that
implements __complex__ doesn't work, because it only
looks for __complex__ when the argument is a classic
instance.  It should always look for __complex__ (but
probably after checking for a complex instance).

See
http://mail.python.org/pipermail/python-dev/2002-June/024898.html
and my reply.

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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-06-06 02:14

Message:
Logged In: YES 
user_id=80475

This patch passes regression and fixes the bug:

class OS:
   def __complex__(self): return 1+2j
class NS(object):
   def __complex__(self): return 3+4j
print map(complex, [5, 6.6, 7+8j, 9L, OS(), NS(), "10+11j"])

Please confirm that I'm using the best way to detect a new-
style class instances with Py_TPFLAGS_HEAPTYPE.

Also, incidental to this bug, which error messages do you 
want for int, float, complex, and long:
-- object can't be converted to float
-- float() needs a string argument
-- float() needs a string or number argument

Right now, the messages are not consistent.  I prefer the 
third style to be used through-out.

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

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