[Python-checkins] r69245 - in python/branches/release30-maint: Lib/decimal.py Lib/test/test_decimal.py Misc/NEWS
raymond.hettinger
python-checkins at python.org
Tue Feb 3 04:50:40 CET 2009
Author: raymond.hettinger
Date: Tue Feb 3 04:50:39 2009
New Revision: 69245
Log:
Register decimals as numbers.Number
Modified:
python/branches/release30-maint/Lib/decimal.py
python/branches/release30-maint/Lib/test/test_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 Feb 3 04:50:39 2009
@@ -135,6 +135,7 @@
]
import copy as _copy
+import numbers as _numbers
try:
from collections import namedtuple as _namedtuple
@@ -3654,6 +3655,12 @@
return self
+# Register Decimal as a kind of Number (an abstract base class).
+# However, do not register it as Real (because Decimals are not
+# interoperable with floats).
+_numbers.Number.register(Decimal)
+
+
##### Context class #######################################################
Modified: python/branches/release30-maint/Lib/test/test_decimal.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_decimal.py (original)
+++ python/branches/release30-maint/Lib/test/test_decimal.py Tue Feb 3 04:50:39 2009
@@ -30,6 +30,7 @@
import pickle, copy
import unittest
from decimal import *
+import numbers
from test.support import (TestSkipped, run_unittest, run_doctest,
is_resource_enabled)
import random
@@ -1389,6 +1390,12 @@
class DecimalPythonAPItests(unittest.TestCase):
+ def test_abc(self):
+ self.assert_(issubclass(Decimal, numbers.Number))
+ self.assert_(not issubclass(Decimal, numbers.Real))
+ self.assert_(isinstance(Decimal(0), numbers.Number))
+ self.assert_(not isinstance(Decimal(0), numbers.Real))
+
def test_pickle(self):
d = Decimal('-3.141590000')
p = pickle.dumps(d)
Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS (original)
+++ python/branches/release30-maint/Misc/NEWS Tue Feb 3 04:50:39 2009
@@ -152,7 +152,8 @@
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.
+ numbers.Real. Instead, it is registered to numbers.Number so that
+ isinstance(d, Number) will work.
- 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