Unary plus operator and __pos__
Erik Max Francis
max at alcyone.com
Tue Sep 28 04:40:14 EDT 2004
Gerrit wrote:
> Erik Max Francis wrote:
>
> > Unary plus is __pos__ for positive, unary minus is __neg__ for
> > negative.
> >
> > The unary plus operator, I'm sure, is a holdover from C. Since the
> > unary plus operator is a no-op for normal numeric values, I would be
> > hesitant to use it to mean something else;
>
> The Decimal class does:
>
> >>> n = Decimal((0, (0, ), 'N'))
> >>> n
> Decimal("sNaN")
> >>> +n
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/python2.4/decimal.py", line 863, in __pos__
> ans = self._check_nans(context=context)
> File "/usr/local/lib/python2.4/decimal.py", line 619, in _check_nans
> 1, self)
> File "/usr/local/lib/python2.4/decimal.py", line 2243, in _raise_error
> raise error, explanation
> decimal.InvalidOperation: sNaN
I don't see how that's at all a useful feature. Besides, one add-on
module as a counterexample doesn't exactly invalidate the point, which
was a personal opinion on a design goal, anyway.
--
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ History is a set of lies agreed upon.
-- Napoleon Bonaparte
More information about the Python-list
mailing list