classification
Title: Decimal should allow leading or trailing spaces.
Type: feature request
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder: Decimal constructor accepts newline terminated strings
View: 1780
Assigned To: Nosy List: marketdickinson, romaia
Priority: normal Keywords:

Created on 2006-07-03 20:27 by romaia, last changed 2008-01-12 03:31 by marketdickinson.

Files
File name Uploaded Description Edit Remove
decimal.diff romaia, 2006-07-03 20:27 simple patch
Messages
msg29029 (view) Author: Ronaldo Francisco Maia (romaia) Date: 2006-07-03 20:27
When creating a Decimal from a string, leading and
trailing spaces should be allowed, as it happens with
int and float:

>>> int(' 1 ')
1
>>> Decimal(' 1 ')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/decimal.py", line 571, in
__new__
    self._sign, self._int, self._exp =
context._raise_error(ConversionSyntax)
  File "/usr/lib/python2.4/decimal.py", line 2267, in
_raise_error
    raise error, explanation
decimal.InvalidOperation


If we look at decimal.py, the code (regex) is already
there, but commented.
msg57824 (view) Author: Mark Dickinson (marketdickinson) Date: 2007-11-25 03:17
This is a feature request rather than a bug.  There's a least one good 
reason not to do this, namely that the specification on which the decimal 
module is based specifically disallows this:  At

http://www2.hursley.ibm.com/decimal/daconvs.html

it says:  "No blanks or other white space characters are permitted in a 
numeric string.", and the "to-number" operation of the specification, 
which converts strings to Decimal instances, is expected only to accept 
numeric strings.

Of course, all the specification requires is that the functionality of to-
number is present in the Decimal module *somewhere*:  currently it's 
implemented by Decimal.__new__, but it would be possible to alter 
Decimal.__new__ to allow leading and trailing spaces, and have a strictly 
conforming to-number implementation elsewhere in the Decimal module.  I 
don't think there's any real benefit to this.  It's easy enough to add a 
call to strip() to the Decimal argument.

I recommend closing this issue as a "won't fix".
msg59780 (view) Author: Mark Dickinson (marketdickinson) Date: 2008-01-12 03:31
I spoke too soon.  This came up again in the discussion for issue #1780 
and there was general support for allowing trailing and leading 
whitespace.

Fixed for Python 2.6, revision 59929
History
Date User Action Args
2008-01-12 03:31:57marketdickinsonsetstatus: open -> closed
resolution: fixed
superseder: Decimal constructor accepts newline terminated strings
messages: + msg59780
2007-11-25 03:17:08marketdickinsonsettype: feature request
messages: + msg57824
nosy: + marketdickinson
2006-07-03 20:27:42romaiacreate