summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-10-14 18:10:56 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-10-14 18:10:56 (GMT)
commit20c049df37da20383bdc36e0de6e58f4ebc53659 (patch)
tree5452fb1422c17d643053f7d9d7a5d3532fc1bd30
parent9c2ce254bb8a2d36657e620b36207f20047accf5 (diff)
downloadcpython-20c049df37da20383bdc36e0de6e58f4ebc53659.zip
cpython-20c049df37da20383bdc36e0de6e58f4ebc53659.tar.gz
cpython-20c049df37da20383bdc36e0de6e58f4ebc53659.tar.bz2
Issue #21855: Fixed the decimal module in unicode disabled build.
-rw-r--r--Lib/decimal.py5
-rw-r--r--Lib/test/test_decimal.py9
2 files changed, 9 insertions, 5 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 19cc50f..07c2cec 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -6035,7 +6035,10 @@ def _parse_format_specifier(format_spec, _localeconv=None):
format_dict['decimal_point'] = '.'
# record whether return type should be str or unicode
- format_dict['unicode'] = isinstance(format_spec, unicode)
+ try:
+ format_dict['unicode'] = isinstance(format_spec, unicode)
+ except NameError:
+ format_dict['unicode'] = False
return format_dict
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 610a696..4dbe62d 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -31,7 +31,7 @@ import pickle, copy
import unittest
from decimal import *
import numbers
-from test.test_support import (run_unittest, run_doctest,
+from test.test_support import (run_unittest, run_doctest, requires_unicode, u,
is_resource_enabled, check_py3k_warnings)
import random
try:
@@ -595,11 +595,12 @@ class DecimalExplicitConstructionTest(unittest.TestCase):
d = nc.create_decimal(prevdec)
self.assertEqual(str(d), '5.00E+8')
+ @requires_unicode
def test_unicode_digits(self):
test_values = {
- u'\uff11': '1',
- u'\u0660.\u0660\u0663\u0667\u0662e-\u0663' : '0.0000372',
- u'-nan\u0c68\u0c6a\u0c66\u0c66' : '-NaN2400',
+ u(r'\uff11'): '1',
+ u(r'\u0660.\u0660\u0663\u0667\u0662e-\u0663') : '0.0000372',
+ u(r'-nan\u0c68\u0c6a\u0c66\u0c66') : '-NaN2400',
}
for input, expected in test_values.items():
self.assertEqual(str(Decimal(input)), expected)