[issue1780] Decimal constructor accepts newline terminated strings
Mark Dickinson
report at bugs.python.org
Thu Jan 10 04:10:36 CET 2008
Mark Dickinson added the comment:
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.
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1780>
__________________________________
More information about the Python-bugs-list
mailing list