diff --git a/Lib/decimal.py b/Lib/decimal.py index 940a9d24d44..c94e1be051f 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -5337,20 +5337,20 @@ ExtendedContext = Context( # other meaning for \d than the numbers [0-9]. import re -_parser = re.compile(r""" # A numeric string consists of: +_parser = re.compile(r""" # A numeric string consists of: # \s* - (?P[-+])? # an optional sign, followed by either... + (?P[-+])? # an optional sign, followed by either... ( - (?=\d|\.\d) # ...a number (with at least one digit) - (?P\d*) # consisting of a (possibly empty) integer part - (\.(?P\d*))? # followed by an optional fractional part - (E(?P[-+]?\d+))? # followed by an optional exponent, or... + (?=[0-9]|\.[0-9]) # ...a number (with at least one digit) + (?P[0-9]*) # having a (possibly empty) integer part + (\.(?P[0-9]*))? # followed by an optional fractional part + (E(?P[-+]?[0-9]+))? # followed by an optional exponent, or... | - Inf(inity)? # ...an infinity, or... + Inf(inity)? # ...an infinity, or... | - (?Ps)? # ...an (optionally signaling) - NaN # NaN - (?P\d*) # with (possibly empty) diagnostic information. + (?Ps)? # ...an (optionally signaling) + NaN # NaN + (?P[0-9]*) # with (possibly empty) diagnostic info. ) # \s* \Z diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 17c6373edf7..74304f70fe4 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -432,6 +432,9 @@ class DecimalExplicitConstructionTest(unittest.TestCase): self.assertEqual(str(Decimal(u'-Inf')), '-Infinity') self.assertEqual(str(Decimal(u'NaN123')), 'NaN123') + #but alternate unicode digits should not + self.assertEqual(str(Decimal(u'\uff11')), 'NaN') + def test_explicit_from_tuples(self): #zero