]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 4998: Decimal should not subclass or register with numbers.Real.
authorRaymond Hettinger <python@rcn.com>
Tue, 20 Jan 2009 07:27:47 +0000 (07:27 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 20 Jan 2009 07:27:47 +0000 (07:27 +0000)
Lib/decimal.py
Misc/NEWS

index 02216702c661f17d81ae0d827d0f26151f2a2759..a931fb93ad4914df876d4f1ec981ce099f94efc0 100644 (file)
@@ -134,7 +134,6 @@ __all__ = [
     'setcontext', 'getcontext', 'localcontext'
 ]
 
-import numbers as _numbers
 import copy as _copy
 
 try:
@@ -500,7 +499,11 @@ def localcontext(ctx=None):
 
 ##### Decimal class #######################################################
 
-class Decimal(_numbers.Real):
+# Do not subclass Decimal from numbers.Real and do not register it as such
+# (because Decimals are not interoperable with floats).  See the notes in
+# numbers.py for more detail.
+
+class Decimal(object):
     """Floating point class for decimal arithmetic."""
 
     __slots__ = ('_exp','_int','_sign', '_is_special')
@@ -1716,14 +1719,10 @@ class Decimal(_numbers.Real):
         >>> round(Decimal('Inf'))
         Traceback (most recent call last):
           ...
-          ...
-          ...
         OverflowError: cannot round an infinity
         >>> round(Decimal('NaN'))
         Traceback (most recent call last):
           ...
-          ...
-          ...
         ValueError: cannot round a NaN
 
         If a second argument n is supplied, self is rounded to n
index 95be83872c1e6a3017a48ee869396f4ceeed0b2e..566bea5a67f5ec6b5dd1b258472a2fa2a149f398 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -99,6 +99,9 @@ Library
   appropriately when it is being used via socket.makefile() objects
   rather than delaying the close by waiting for garbage collection to do it.
 
+- Issue #4998: Decimal no longer subclasses from or is registered to
+  numbers.Real.
+
 - Issue #4867: Fixed a crash in ctypes when passing a string to a
   function without defining argtypes.