Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-10 Thread M.-A. Lemburg
Nick Coghlan wrote: Guido van Rossum wrote: No, the reason is that if we did this with exceptions, it would be liable to mask errors; an exception does not necessarily originate immediately with the code you invoked, it could have been raised by something else that was invoked by that code. The spe

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-07 Thread Nick Coghlan
Greg Ewing wrote: Is there some reason why Context couldn't invoke the binary operator methods using binary operators, rather than calling their methods directly? I had a similar idea, but then I remembered that the whole point of invoking the methods through a specific Context is to override the

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-04 Thread Nick Coghlan
Michael Hudson wrote: PS: this beahviour seems odd already: decimal.getcontext().abs(1) Traceback (most recent call last): File "", line 1, in ? File "/Users/mwh/Source/python/dist/src/Lib/decimal.py", line 2321, in abs return a.__abs__(context=self) TypeError: wrapper __abs__ doesn't take

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-04 Thread Nick Coghlan
Guido van Rossum wrote: No, the reason is that if we did this with exceptions, it would be liable to mask errors; an exception does not necessarily originate immediately with the code you invoked, it could have been raised by something else that was invoked by that code. The special value NotImplem

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-02 Thread Guido van Rossum
> Nick Craig-Wood wrote: > > Why is it like that? Nick Coghlan replied: > Speed, I assume - if it was exception based, then *every* operation > effectively > gets wrapped in a try/except block. Yikes! No, the reason is that if we did this with exceptions, it would be liable to mask errors; an ex

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-02 Thread Michael Hudson
Nick Coghlan <[EMAIL PROTECTED]> writes: > Neil Schemenauer wrote: >> IMO, Decimal should >> be returning NotImplemented instead of raising TypeError. > > I agree, but I'm also interested in the fact that nobody commented on > this before Python 2.4 went out. I read the reference page on numeric

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-02 Thread Nick Coghlan
Nick Craig-Wood wrote: Why is it like that? Speed, I assume - if it was exception based, then *every* operation effectively gets wrapped in a try/except block. Yikes! Also, for C implementations, the error return is fairly natural. It's only when implementing operations in Python that it bites.

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-02 Thread Nick Coghlan
Neil Schemenauer wrote: IMO, Decimal should be returning NotImplemented instead of raising TypeError. I agree, but I'm also interested in the fact that nobody commented on this before Python 2.4 went out. I read the reference page on numeric coercion more times than I care to count, and still di

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-02 Thread Nick Craig-Wood
On Tue, Mar 01, 2005 at 05:55:50PM -0500, Neil Schemenauer wrote: > On Tue, Mar 01, 2005 at 11:45:43PM +1000, Nick Coghlan wrote: > > Interesting. In that case, my other suggestion was to have raising > > NotImplementedError from a special method be the equivalent of returning > > NotImplemented

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-01 Thread Neil Schemenauer
On Tue, Mar 01, 2005 at 11:45:43PM +1000, Nick Coghlan wrote: > Interesting. In that case, my other suggestion was to have raising > NotImplementedError from a special method be the equivalent of returning > NotImplemented (which makes life much easier for a class like Decimal which > has an int

Re: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-01 Thread Nick Coghlan
Raymond Hettinger wrote: Try to address this in a larger context than decimal. The same sort of logic is present in sets.py and in datetime objects. Interesting. In that case, my other suggestion was to have raising NotImplementedError from a special method be the equivalent of returning NotImpl

RE: [Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-01 Thread Raymond Hettinger
> A recent question on c.l.p pointed out that the 2.4 Decimal implementation > raises TypeError directly for operator arguments it doesn't understand, > instead > of returning NotImplemented. > > Obviously, this creates problems for anyone trying to define a class that > 'plays > nicely' with Deci

[Python-Dev] Decimal & returning NotImplemented (or not)

2005-03-01 Thread Nick Coghlan
A recent question on c.l.p pointed out that the 2.4 Decimal implementation raises TypeError directly for operator arguments it doesn't understand, instead of returning NotImplemented. Obviously, this creates problems for anyone trying to define a class that 'plays nicely' with Decimal (but does