classification
Title: Decimal(unicode)
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: facundobatista, mark.dickinson, phd
Priority: normal Keywords:

Created on 2008-03-25 15:37 by phd, last changed 2008-03-25 21:38 by mark.dickinson. This issue is now closed.

Messages (5)
msg64488 - (view) Author: Oleg Broytman (phd) * Date: 2008-03-25 15:37
Decimal(u'123').to_eng_string() returns unicode in Python 2.5.2. That's
probably due to the optimization in decimal module, after which decimal
stores coefficient (mantissa) as a str, and doesn't coerce input to str.

See the thread at
http://mail.python.org/pipermail/python-dev/2008-March/078189.html
msg64490 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-03-25 15:51
Decimal needs to grow something like the following near the top of the
module:

try:
  _bytes = bytes
except NameError: # 2.5 or earlier
  _bytes = str

and then use _bytes instead of str as appropriate throughout the rest of
the module.

This will solve the actual problem, and scales well with 2.6 and 3k.
msg64504 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2008-03-25 18:41
I'm not sure that converting to bytes for Python 3.0 is going to
be a simple change.  For one thing, most of the arithmetic functions
have to do the reverse conversion (int -> str/bytes) at some point.

At the moment, an int -> bytes conversion has to go through unicode (I 
think);  something like  bytes(str(n), 'ascii'), so it's not 100% clear
that replacing str with bytes is going to produce a speed gain.

For now, I'll get the fix for the 2.5/2.6 problem in (it only
involves changing 3 lines in decimal.py, along with adding a few
extra tests).

Changing str -> bytes in 3.0 needs more careful thought, and some 
benchmarking.
msg64505 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2008-03-25 19:02
str -> unicode regression fixed in r61904, r61906.

(I backported the fix to 2.5;  it's not absolutely clear that it's worth 
it, but this *is* a bug, and it seems worth not letting the various 
decimal.py versions diverge too much.)
msg64522 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2008-03-25 21:38
The original bug here is fixed, so I'm closing this issue.  I've opened
a separate issue (issue 2486) for discussing changing the Decimal 
coefficient from str to bytes.
History
Date User Action Args
2008-03-25 21:38:31mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg64522
2008-03-25 19:02:43mark.dickinsonsetmessages: + msg64505
2008-03-25 18:41:54mark.dickinsonsetmessages: + msg64504
2008-03-25 15:51:08facundobatistasetnosy: + facundobatista
messages: + msg64490
2008-03-25 15:42:08mark.dickinsonsetassignee: mark.dickinson
nosy: + mark.dickinson
versions: + Python 2.6
2008-03-25 15:37:13phdcreate