aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/_pydecimal.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/_pydecimal.py')
-rw-r--r--Lib/_pydecimal.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py
index 4b09207eca6..9b8e42a2342 100644
--- a/Lib/_pydecimal.py
+++ b/Lib/_pydecimal.py
@@ -6096,7 +6096,7 @@ _parser = re.compile(r""" # A numeric string consists of:
(?P<diag>\d*) # with (possibly empty) diagnostic info.
)
# \s*
- \Z
+ \z
""", re.VERBOSE | re.IGNORECASE).match
_all_zeros = re.compile('0*$').match
@@ -6120,11 +6120,15 @@ _parse_format_specifier_regex = re.compile(r"""\A
(?P<no_neg_0>z)?
(?P<alt>\#)?
(?P<zeropad>0)?
-(?P<minimumwidth>(?!0)\d+)?
+(?P<minimumwidth>\d+)?
(?P<thousands_sep>[,_])?
-(?:\.(?P<precision>0|(?!0)\d+))?
+(?:\.
+ (?=[\d,_]) # lookahead for digit or separator
+ (?P<precision>\d+)?
+ (?P<frac_separators>[,_])?
+)?
(?P<type>[eEfFgGn%])?
-\Z
+\z
""", re.VERBOSE|re.DOTALL)
del re
@@ -6215,6 +6219,9 @@ def _parse_format_specifier(format_spec, _localeconv=None):
format_dict['grouping'] = [3, 0]
format_dict['decimal_point'] = '.'
+ if format_dict['frac_separators'] is None:
+ format_dict['frac_separators'] = ''
+
return format_dict
def _format_align(sign, body, spec):
@@ -6334,6 +6341,11 @@ def _format_number(is_negative, intpart, fracpart, exp, spec):
sign = _format_sign(is_negative, spec)
+ frac_sep = spec['frac_separators']
+ if fracpart and frac_sep:
+ fracpart = frac_sep.join(fracpart[pos:pos + 3]
+ for pos in range(0, len(fracpart), 3))
+
if fracpart or spec['alt']:
fracpart = spec['decimal_point'] + fracpart