diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py index ff23322ed5..d8e94a727d 100644 --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -547,7 +547,7 @@ def __new__(cls, value="0", context=None): # From a string # REs insist on real strings, so we can too. if isinstance(value, str): - m = _parser(value.strip().replace("_", "")) + m = _parser(value.strip()) if m is None: if context is None: context = getcontext() @@ -6114,20 +6114,20 @@ def _convert_for_comparison(self, other, equality_op=False): # lookahead expression '(?=\d|\.\d)' checks this. 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*) # having a (possibly empty) integer part - (\.(?P\d*))? # followed by an optional fractional part - (E(?P[-+]?\d+))? # followed by an optional exponent, or... + (?=\d|\.\d) # ...a number (with at least one digit) + (?P\d*|\d+(_\d+)*) # having a (possibly empty) integer part + (\.(?P\d*|\d+(_\d+)*))? # followed by an optional fractional part + (E(?P[-+]?\d+(_\d+)*))? # 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 info. + (?Ps)? # ...an (optionally signaling) + NaN # NaN + (?P\d*|\d+(_\d+)*) # with (possibly empty) diagnostic info. ) # \s* \Z