[Python-checkins] r68800 - in python/branches/release30-maint: Lib/decimal.py Misc/NEWS

raymond.hettinger python-checkins at python.org
Tue Jan 20 08:27:47 CET 2009


Author: raymond.hettinger
Date: Tue Jan 20 08:27:47 2009
New Revision: 68800

Log:
Issue 4998: Decimal should not subclass or register with numbers.Real.

Modified:
   python/branches/release30-maint/Lib/decimal.py
   python/branches/release30-maint/Misc/NEWS

Modified: python/branches/release30-maint/Lib/decimal.py
==============================================================================
--- python/branches/release30-maint/Lib/decimal.py	(original)
+++ python/branches/release30-maint/Lib/decimal.py	Tue Jan 20 08:27:47 2009
@@ -134,7 +134,6 @@
     'setcontext', 'getcontext', 'localcontext'
 ]
 
-import numbers as _numbers
 import copy as _copy
 
 try:
@@ -500,7 +499,11 @@
 
 ##### 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 @@
         >>> 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

Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS	(original)
+++ python/branches/release30-maint/Misc/NEWS	Tue Jan 20 08:27:47 2009
@@ -99,6 +99,9 @@
   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.
 


More information about the Python-checkins mailing list