[Python-ideas] Changing Decimal.__pos__ and Decimal.__neg__ [Was: Re: Python Numbers as Human Concept Decimal System]
Mark Dickinson
dickinsm at gmail.com
Mon Mar 10 14:30:47 CET 2014
On Mon, Mar 10, 2014 at 10:16 AM, Oscar Benjamin <oscar.j.benjamin at gmail.com
> wrote:
> On 10 March 2014 08:32, Mark Dickinson <dickinsm at gmail.com> wrote:
> >
> > Another option would be to change the behaviour of + and - on Decimal
> > objects by binding `__pos__` and `__neg__` to the specification's 'copy'
> and
> > 'copy-negate' operations instead of (as currently) to the 'plus' and
> 'minus'
> > operations. Those behaviours are more in keeping with the way that +
> and -
> > operate on other objects.
>
> Hi Mark and thanks for responding,
>
> Do you think it's really feasible to make such a change?
Probably not. :-( As you point out, there are significant backward
compatibility issues. It's the solution I'd adopt if those concerns didn't
exists, and the one I'd still look for a way to get to even *with* those
concerns, but the level of breakage may make this out of the question. I
doubt we're going to get to Decimal literals without breaking at least
*some* code, but this may be too much breakage.
I guess I have ulterior motives; (ab)using '+' to mean 'round to the
current context' has always felt way too implicit for my tastes, and I'd
jump at the chance to see it go away. The unconventional behaviour with
respect to signed zeros bugs me, too.
>>> -0.0
-0.0
>>> -Decimal(0.0) # negative sign mysteriously disappears.
Decimal('0')
It's perfectly legitimate, and part of the standard, but ... ugh. I argued
with Mike Cowlishaw about it at one point. I lost.
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140310/a32fd8db/attachment-0001.html>
More information about the Python-ideas
mailing list