diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/decimal.py | 14 | ||||
-rw-r--r-- | Lib/httplib.py | 4 | ||||
-rw-r--r-- | Lib/idlelib/configHandler.py | 2 | ||||
-rw-r--r-- | Lib/numbers.py | 26 |
4 files changed, 45 insertions, 1 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 873f7c069e..2745065910 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1518,6 +1518,20 @@ class Decimal(_numbers.Real, _numbers.Inexact): __trunc__ = __int__ + @property + def real(self): + return self + + @property + def imag(self): + return Decimal(0) + + def conjugate(self): + return self + + def __complex__(self): + return complex(float(self)) + def _fix_nan(self, context): """Decapitate the payload of a NaN to fit the context""" payload = self._int diff --git a/Lib/httplib.py b/Lib/httplib.py index 932152277a..bb873e4760 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -596,6 +596,10 @@ class HTTPResponse: ### note: we shouldn't have any trailers! while True: line = self.fp.readline() + if not line: + # a vanishingly small number of sites EOF without + # sending the trailer + break if line == b"\r\n": break diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py index 9c106eb1d1..49065789c1 100644 --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -143,7 +143,7 @@ class IdleUserConfParser(IdleConfParser): try: cfgFile = open(fname, 'w') except IOError: - fname.unlink() + os.unlink(fname) cfgFile = open(fname, 'w') self.write(cfgFile) else: diff --git a/Lib/numbers.py b/Lib/numbers.py index b5150d22ff..a4b7a6d260 100644 --- a/Lib/numbers.py +++ b/Lib/numbers.py @@ -46,6 +46,32 @@ Inexact.register(float) # Inexact.register(decimal.Decimal) +## Notes on Decimal and it how relates to the numeric tower +## -------------------------------------------------------- +## Decimal is Real except that it does not support rich comparisons. +## +## Decimal has some of the characteristics of Integrals. It provides +## logical operations but not as operators. The logical operations only apply +## to a subset of decimals (those that are non-negative, have a zero exponent, +## and have digits that are only 0 or 1). It does provide __long__() and +## a three argument form of __pow__ that includes exactness guarantees. +## It does not provide an __index__() method. +## +## Depending on context, decimal operations may be exact or inexact. +## +## When decimal is run in a context with small precision and automatic rounding, +## it is Inexact. See the "Floating point notes" section of the decimal docs +## for an example of losing the associative and distributive properties of +## addition. +## +## When decimal is used for high precision integer arithmetic, it is Exact. +## When the decimal used as fixed-point, it is Exact. +## When it is run with sufficient precision, it is Exact. +## When the decimal.Inexact trap is set, decimal operations are Exact. +## For an example, see the float_to_decimal() recipe in the "Decimal FAQ" +## section of the docs -- it shows an how traps are used in conjunction +## with variable precision to reliably achieve exact results. + class Complex(Number): """Complex defines the operations that work on the builtin complex type. |