mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #7094: Add alternate ('#') flag to __format__ methods for float, complex and Decimal. Allows greater control over when decimal points appear. Added to make transitioning from %-formatting easier. '#g' still has a problem with Decimal which I'll fix soon.
This commit is contained in:
parent
c1d98d6850
commit
984bb58000
9 changed files with 87 additions and 36 deletions
|
@ -5991,7 +5991,7 @@ _exact_half = re.compile('50*$').match
|
|||
#
|
||||
# A format specifier for Decimal looks like:
|
||||
#
|
||||
# [[fill]align][sign][0][minimumwidth][,][.precision][type]
|
||||
# [[fill]align][sign][#][0][minimumwidth][,][.precision][type]
|
||||
|
||||
_parse_format_specifier_regex = re.compile(r"""\A
|
||||
(?:
|
||||
|
@ -5999,6 +5999,7 @@ _parse_format_specifier_regex = re.compile(r"""\A
|
|||
(?P<align>[<>=^])
|
||||
)?
|
||||
(?P<sign>[-+ ])?
|
||||
(?P<alt>\#)?
|
||||
(?P<zeropad>0)?
|
||||
(?P<minimumwidth>(?!0)\d+)?
|
||||
(?P<thousands_sep>,)?
|
||||
|
@ -6214,7 +6215,7 @@ def _format_number(is_negative, intpart, fracpart, exp, spec):
|
|||
|
||||
sign = _format_sign(is_negative, spec)
|
||||
|
||||
if fracpart:
|
||||
if fracpart or spec['alt']:
|
||||
fracpart = spec['decimal_point'] + fracpart
|
||||
|
||||
if exp != 0 or spec['type'] in 'eE':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue