[Python-ideas] Changing Decimal.__pos__ and Decimal.__neg__ [Was: Re: Python Numbers as Human Concept Decimal System]

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Mar 10 15:21:22 CET 2014


On 10 March 2014 13:55,  <random832 at fastmail.us> wrote:
> On Mon, Mar 10, 2014, at 9:30, Mark Dickinson wrote:
>>
>> 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.

I tend to agree. How would you prefer to spell it? I guess something like:

    return d.contextround()

I've sometimes used it in a polymorphic kind of way so that a function
does the right thing with Decimal but also works with float/int etc.
(with the + just being a no-op). That's not really an argument against
your point though.

> It occurs to me that there is an unprecedented opportunity to make warts
> "go away" - making Decimal a "first-class citizen" suggests moving it
> from the decimal module to a built-in type. Any backwards-incompatible
> change you want to make, you can give programs importing decimal the old
> behavior, and reserve the new behavior for the new type in builtins.

That's also possible. I wonder what a good name for a new Decimal type
would be. It's unfortunate that calling it 'decimal' would sort of
conflict with people doing 'import decimal'.


Oscar


More information about the Python-ideas mailing list