[Python-Dev] A Horrible Inconsistency

Facundo Batista facundobatista at gmail.com
Fri May 26 17:37:02 CEST 2006


2006/5/25, Fredrik Lundh <fredrik at pythonware.com>:

>  >>> -1 * (1, 2, 3)
> ()
>  >>> -(1, 2, 3)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: bad operand type for unary -
>
> We Really Need To Fix This!

I don't see here an inconsistency. The operator "*" is not a
multiplier as in math, it's more a "repeater", so math multiplier
attributes don't apply here.

There's no concept like "negative tuple" or "positive tuple", so the
second example is clearly an error.

Regarding the first line, in the docs expresely says "Values of n less
than 0 are treated as 0".

I think that we can do one of the following, when we found "-1 * (1, 2, 3)":

- Treat -1 as 0 and return an empty tuple (actual behavior).
- Treat the negative as a reverser, so we get back (3, 2, 1).
- Raise an error.

Personally, +0 on the third.

Regards,

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


More information about the Python-Dev mailing list