Mark Dickinson <[email protected]> added the comment:
Thanks for the patch!
Rather than using the Decimal constructor, I think you should convert use
_convert_other(..., raiseit=True): the Decimal constructor converts strings
and tuples, as well as ints and longs, while _convert_other only converts ints
and longs. Note also that the conversion shouldn't depend on the current
context; only the operation itself needs that.
Maybe it would be worth adding some tests to ensure that e.g.,
MyContext.add('4.5', 123)
raises TypeError as expected?
I agree with the observation that it's usually only necessary to convert the
first argument (since the Decimal method itself converts the second).
If you like, you could also usefully deal with the NotImplemented return value
by turning it into a TypeError (i.e., in the context method, check for a
NotImplemented return value, and raise TypeError there if necessary). This is
only needed for the double underscore methods __add__, __sub__, etc.
associated with Python's binary operators; the other methods shouldn't ever
return NotImplemented.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue7633>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com