diff options
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r-- | Lib/fractions.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py index 8163e3bb594..a8c67068522 100644 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -168,9 +168,9 @@ _FLOAT_FORMAT_SPECIFICATION_MATCHER = re.compile(r""" # A '0' that's *not* followed by another digit is parsed as a minimum width # rather than a zeropad flag. (?P<zeropad>0(?=[0-9]))? - (?P<minimumwidth>0|[1-9][0-9]*)? + (?P<minimumwidth>[0-9]+)? (?P<thousands_sep>[,_])? - (?:\.(?P<precision>0|[1-9][0-9]*))? + (?:\.(?P<precision>[0-9]+))? (?P<presentation_type>[eEfFgG%]) """, re.DOTALL | re.VERBOSE).fullmatch @@ -238,11 +238,6 @@ class Fraction(numbers.Rational): self._denominator = 1 return self - elif isinstance(numerator, numbers.Rational): - self._numerator = numerator.numerator - self._denominator = numerator.denominator - return self - elif (isinstance(numerator, float) or (not isinstance(numerator, type) and hasattr(numerator, 'as_integer_ratio'))): @@ -278,6 +273,11 @@ class Fraction(numbers.Rational): if m.group('sign') == '-': numerator = -numerator + elif isinstance(numerator, numbers.Rational): + self._numerator = numerator.numerator + self._denominator = numerator.denominator + return self + else: raise TypeError("argument should be a string or a Rational " "instance or have the as_integer_ratio() method") @@ -504,6 +504,9 @@ class Fraction(numbers.Rational): trim_point = not alternate_form exponent_indicator = "E" if presentation_type in "EFG" else "e" + if align == '=' and fill == '0': + zeropad = True + # Round to get the digits we need, figure out where to place the point, # and decide whether to use scientific notation. 'point_pos' is the # relative to the _end_ of the digit string: that is, it's the number |