diff options
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 9f37e4fa48..324e4f91ca 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -116,6 +116,9 @@ __all__ = [ # Two major classes 'Decimal', 'Context', + # Named tuple representation + 'DecimalTuple', + # Contexts 'DefaultContext', 'BasicContext', 'ExtendedContext', @@ -124,6 +127,9 @@ __all__ = [ 'Inexact', 'Rounded', 'Subnormal', 'Overflow', 'Underflow', 'FloatOperation', + # Exceptional conditions that trigger InvalidOperation + 'DivisionImpossible', 'InvalidContext', 'ConversionSyntax', 'DivisionUndefined', + # Constants for use in setting up contexts 'ROUND_DOWN', 'ROUND_HALF_UP', 'ROUND_HALF_EVEN', 'ROUND_CEILING', 'ROUND_FLOOR', 'ROUND_UP', 'ROUND_HALF_DOWN', 'ROUND_05UP', @@ -140,9 +146,8 @@ __all__ = [ __version__ = '1.70' # Highest version of the spec this complies with # See http://speleotrove.com/decimal/ -__libmpdec_version__ = "2.4.0" # compatible libmpdec version +__libmpdec_version__ = "2.4.1" # compatible libmpdec version -import copy as _copy import math as _math import numbers as _numbers import sys @@ -704,8 +709,7 @@ class Decimal(object): raise TypeError("Cannot convert %r to Decimal" % value) - # @classmethod, but @decorator is not valid Python 2.3 syntax, so - # don't use it (see notes on Py2.3 compatibility at top of file) + @classmethod def from_float(cls, f): """Converts a float to a decimal number, exactly. @@ -744,7 +748,6 @@ class Decimal(object): return result else: return cls(result) - from_float = classmethod(from_float) def _isnan(self): """Returns whether the number is not actually one. @@ -964,13 +967,12 @@ class Decimal(object): return self._cmp(other) >= 0 def compare(self, other, context=None): - """Compares one to another. + """Compare self to other. Return a decimal value: - -1 => a < b - 0 => a = b - 1 => a > b - NaN => one is NaN - Like __cmp__, but returns Decimal instances. + a or b is a NaN ==> Decimal('NaN') + a < b ==> Decimal('-1') + a == b ==> Decimal('0') + a > b ==> Decimal('1') """ other = _convert_other(other, raiseit=True) @@ -3772,6 +3774,8 @@ class Decimal(object): if self._is_special: sign = _format_sign(self._sign, spec) body = str(self.copy_abs()) + if spec['type'] == '%': + body += '%' return _format_align(sign, body, spec) # a type of None defaults to 'g' or 'G', depending on context |