Nick Coghlan wrote:
Nick Coghlan wrote:

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.

Then again, maybe it's not so bad:

Py> class C:
...   def __add__(self, other):
...     print "OK!"
...   __radd__ = __add__
...
Py> x = decimal.Decimal()
Py> C() + x
OK!
Py> x + C()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python24\lib\decimal.py", line 906, in __add__
    other = _convert_other(other)
  File "C:\Python24\lib\decimal.py", line 2863, in _convert_other
    raise TypeError, "You can interact Decimal only with int, long or Decimal da
ta types."
TypeError: You can interact Decimal only with int, long or Decimal data types.

Py> x = friendly_decimal.Decimal()
Py> C() + x
OK!
Py> x + C()
OK!

Cheers,
Nick.
http://boredomandlaziness.skystorm.net/misc/friendly_decimal.py

--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
            http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to