Decimal, __radd__, and custom numeric types...

Nick Coghlan ncoghlan at iinet.net.au
Tue Mar 1 08:17:45 EST 2005


Batista, Facundo wrote:
> [Nick Coghlan]
> 
> #- >> a) Checking that replacing the relevant "raise TypeError"
> #- calls in
> #- >> Lib/Decimal.py with "return NotImplemented" gives you friendlier
> #- >> behaviour.
> #- >
> #- >
> #- > It turns out this isn't really practical - there's too
> #- much code in the
> #- > module relying on those TypeErrors being raised.
> #-
> #- ...
> #-
> #- Py> x = friendly_decimal.Decimal()
> #- Py> C() + x
> #- OK!
> #- Py> x + C()
> #- OK!
> 
> Nick, did you try the test cases with this modification?

Yep - and I was pleasantly surprised when they all passed with -udecimal, too.

My implementation is a bit hackish though - if this gets fixed for real, it 
should be possible to devise something that doesn't trample all over performance 
like I'm sure the version I linked to does.

Anyway, I've put the question to python-dev if you'd like to chime in over 
there. It's still your module after all :)

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list