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, gvanrossum, mark.dickinson, rhettinger
Date 2008-01-10.03:10:34
SpamBayes Score 0.02496301
Marked as misclassified No
Message-id <1199934636.55.0.591981289941.issue1780@psf.upfronthosting.co.za>
In-reply-to
Content
In the spirit of making the Decimal constructor match the rest of the language, 
can I propose another change:  make Decimal("not a decimal") raise a 
ValueError.

Currently, Decimal("not a decimal") either raises InvalidOperation or returns a 
Decimal NaN, depending on whether the InvalidOperation trap is set in the 
current context or not.  This behaviour presumably again comes directly from 
the specification, but as pointed out already Decimal.__new__ doesn't need to 
rigidly follow the specification---we just need to make sure that the 
functionality of to-number is present somewhere (and create_decimal seems like 
a good candidate for that).  It seems to me that:

Decimal.__new__ shouldn't care about the current context.

The fact that __new__ takes a context parameter at the moment is potentially 
confusing:  one might reasonably expect that passing a context to __new__ would 
result in the Decimal being rounded to fit that context (as happens with 
create_decimal).  In fact, the *only* reason the context argument is there 
because it's needed to raise InvalidOperation;  if the first argument to 
__new__ is valid then the context is entirely unused.
History
Date User Action Args
2008-01-10 03:10:36mark.dickinsonsetspambayes_score: 0.024963 -> 0.02496301
recipients: + mark.dickinson, gvanrossum, rhettinger, facundobatista
2008-01-10 03:10:36mark.dickinsonsetspambayes_score: 0.024963 -> 0.024963
messageid: <1199934636.55.0.591981289941.issue1780@psf.upfronthosting.co.za>
2008-01-10 03:10:35mark.dickinsonlinkissue1780 messages
2008-01-10 03:10:34mark.dickinsoncreate