From fa1f6b69dde18b90429922cbc40320483e020aae Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 20 Jan 2009 07:27:47 +0000 Subject: [PATCH] Issue 4998: Decimal should not subclass or register with numbers.Real. --- Lib/decimal.py | 11 +++++------ Misc/NEWS | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Lib/decimal.py b/Lib/decimal.py index 02216702c661..a931fb93ad49 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -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 diff --git a/Misc/NEWS b/Misc/NEWS index 95be83872c1e..566bea5a67f5 100644 --- 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. -- 2.47.3