[Python-checkins] r64655 - in python/trunk/Lib: decimal.py test/test_decimal.py

mark.dickinson python-checkins at python.org
Wed Jul 2 11:37:02 CEST 2008


Author: mark.dickinson
Date: Wed Jul 2 11:37:01 2008
New Revision: 64655
Log:
Replace occurrences of '\d' with '[0-9]' in Decimal regex, to make sure 
that the behaviour of Decimal doesn't change if/when re.UNICODE becomes 
assumed in Python 3.0.
Also add a check that alternative Unicode digits (e.g. u'\N{FULLWIDTH 
DIGIT ONE}') are *not* accepted in a numeric string.
Modified:
 python/trunk/Lib/decimal.py
 python/trunk/Lib/test/test_decimal.py
Modified: python/trunk/Lib/decimal.py
==============================================================================
--- python/trunk/Lib/decimal.py	(original)
+++ python/trunk/Lib/decimal.py	Wed Jul 2 11:37:01 2008
@@ -5337,20 +5337,20 @@
 # 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<sign>[-+])? # an optional sign, followed by either...
+ (?P<sign>[-+])? # an optional sign, followed by either...
 (
- (?=\d|\.\d) # ...a number (with at least one digit)
- (?P<int>\d*) # consisting of a (possibly empty) integer part
- (\.(?P<frac>\d*))? # followed by an optional fractional part
- (E(?P<exp>[-+]?\d+))? # followed by an optional exponent, or...
+ (?=[0-9]|\.[0-9]) # ...a number (with at least one digit)
+ (?P<int>[0-9]*) # having a (possibly empty) integer part
+ (\.(?P<frac>[0-9]*))? # followed by an optional fractional part
+ (E(?P<exp>[-+]?[0-9]+))? # followed by an optional exponent, or...
 |
- Inf(inity)? # ...an infinity, or...
+ Inf(inity)? # ...an infinity, or...
 |
- (?P<signal>s)? # ...an (optionally signaling)
- NaN # NaN
- (?P<diag>\d*) # with (possibly empty) diagnostic information.
+ (?P<signal>s)? # ...an (optionally signaling)
+ NaN # NaN
+ (?P<diag>[0-9]*) # with (possibly empty) diagnostic info.
 )
 # \s*
 \Z
Modified: python/trunk/Lib/test/test_decimal.py
==============================================================================
--- python/trunk/Lib/test/test_decimal.py	(original)
+++ python/trunk/Lib/test/test_decimal.py	Wed Jul 2 11:37:01 2008
@@ -432,6 +432,9 @@
 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


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /