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.

classification
Title: Decimal should allow leading or trailing spaces.
Type: enhancement Stage:
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: mark.dickinson, romaia
Priority: normal Keywords:

Created on 2006-07-03 20:27 by romaia, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
decimal.diff romaia, 2006-07-03 20:27 simple patch
Messages (3)
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 (mark.dickinson) * (Python committer) 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 (mark.dickinson) * (Python committer) 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
2022-04-11 14:56:18adminsetgithub: 43606
2008-01-12 03:31:57mark.dickinsonsetstatus: open -> closed
resolution: fixed
superseder: Decimal constructor accepts newline terminated strings
messages: + msg59780
2007-11-25 03:17:08mark.dickinsonsettype: enhancement
messages: + msg57824
nosy: + mark.dickinson
2006-07-03 20:27:42romaiacreate