This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients facundobatista, mark.dickinson, rhettinger, skrah
Date 2009-08-28.14:26:58
SpamBayes Score 1.5564217e-12
Marked as misclassified No
Message-id <1251469621.38.0.248001245965.issue6795@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for the reports.

Issue 1. If this is going to be changed, I'd rather see 
int(Decimal('nan')) raise ValueError (just as int(float('nan')) does) 
than return None.

Conversions from Decimal to native integers lie outside the scope of the 
standard, so there's not much help there.  However, precisely *because* 
they lie outside the standard, it seems wrong to be raising a Decimal 
exception (Decimal.InvalidContext) here.  It's also inconsistent with 
the treatment of infinities:  int(Decimal('infinity')) currently gives 
an OverflowError.

Given the lack of guidance from the decimal standard, the next place to 
turn is probably IEEE 754.  IEEE 754-2008, section 5.8 ("Details of 
conversions from floating-point to integer formats") says: 

"""When a NaN or infinite operand cannot be represented in the 
destination format and this cannot otherwise be indicated, the invalid 
operation exception shall be signaled."""

As far as I can tell, when the invalid-operation trap is disabled, the 
return value is undefined in this case (see 7.2(i) in IEEE 754-2008).

But in Python this error condition *can* 'otherwise be indicated', by 
raising a suitable Python exception.  So I propose changing the decimal 
module in 2.7 and 3.2 so that int(Decimal('nan')) and 
long(Decimal('nan')) raise ValueError.

Raymond, Facundo:  any thoughts on this?


Issue 2. A clear bug; will fix.  Thanks.


Issue 3. I can't see how this could cause any real problems, since you'd 
get an error as soon as you tried to use a bogus context.  Further, an 
explicit typecheck goes against Python's duck-typing philosophy:  a 
suitably crazy and misguided person ought to be able to create their own 
'quacks like a context' class, not necessarily inheriting from 
Decimal.Context, and pass this into setcontext in place of a real 
context.  I'm -0 on changing this.
History
Date User Action Args
2009-08-28 14:27:01mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, facundobatista, skrah
2009-08-28 14:27:01mark.dickinsonsetmessageid: <1251469621.38.0.248001245965.issue6795@psf.upfronthosting.co.za>
2009-08-28 14:26:59mark.dickinsonlinkissue6795 messages
2009-08-28 14:26:58mark.dickinsoncreate