[Python-3000] Is this a bug ?

Amaury Forgeot d'Arc amauryfa at gmail.com
Tue Apr 8 15:20:33 CEST 2008


Hello,

Anand Balachandran Pillai wrote:
> While playing around with true & floor division in Py3k...
>
>  Python 3.0a4+ (py3k:62126, Apr  3 2008, 16:28:40)
>  [GCC 4.1.2 20070626 (Red Hat 4.1.2-13)] on linux2
>  Type "help", "copyright", "credits" or "license" for more information.
>  >>> x=2+0j
>  >>> y=3+0j
>  >>> x / y
>  (0.66666666666666663+0j)
>  >>> x//y
>  Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>  TypeError: can't take floor of complex number.
>  >>> x.__floordiv__(y)
>  Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>  TypeError: can't take floor of complex number.
>  >>> x.__divmod__(y)
>  Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>  TypeError: can't take floor or mod of complex number.
>
>  In Python2.5,
>
>  [anand at localhost py3k]$ python2.5
>  Python 2.5.1 (r251:54863, Sep  6 2007, 17:27:08)
>  [GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2
>  Type "help", "copyright", "credits" or "license" for more information.
>  >>> x=2+0j
>  >>> y=3+0j
>  >>> x/y
>  (0.66666666666666663+0j)
>  >>> x//y
>  __main__:1: DeprecationWarning: complex divmod(), // and % are deprecated
>  0j
>  >>> x.__floordiv__(y)
>  0j
>  >>> x.__divmod__(y)
>  (0j, (2+0j))
>
>  Shouldn't Py3k also return 0j for floor division ? If it does not want to do
>  floor division/divmod for complex numbers, shouldn't the exception
>  error be more descriptive ? Or is this the expected behavior ?

Yes, the DeprecationWarning has turned into a real error.
This is the normal evolution of python 3.0.

Then, I find the message quite descriptive:
    >>> divmod(x,y)
    TypeError: can't take floor or mod of complex number.
What message would you want in this case?

-- 
Amaury Forgeot d'Arc


More information about the Python-3000 mailing list