summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-02-03 03:54:28 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-02-03 03:54:28 (GMT)
commit82417ca9b257133e37e5339b29f67160ad568722 (patch)
treec7df28886eaf7eb043f30613bcffacc88c554317
parent2fad8016baa72371bb7fb4b9dabc204559f9968f (diff)
downloadcpython-82417ca9b257133e37e5339b29f67160ad568722.zip
cpython-82417ca9b257133e37e5339b29f67160ad568722.tar.gz
cpython-82417ca9b257133e37e5339b29f67160ad568722.tar.bz2
Register decimals as numbers.Number
-rw-r--r--Lib/decimal.py7
-rw-r--r--Lib/test/test_decimal.py7
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 4f9be21..c46037e 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -136,6 +136,7 @@ __all__ = [
import copy as _copy
import math as _math
+import numbers as _numbers
try:
from collections import namedtuple as _namedtuple
@@ -3695,6 +3696,12 @@ def _dec_from_triple(sign, coefficient, exponent, special=False):
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 #######################################################
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 798f4d8..f40de8f 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -30,6 +30,7 @@ import os, sys
import pickle, copy
import unittest
from decimal import *
+import numbers
from test.support import (TestSkipped, run_unittest, run_doctest,
is_resource_enabled)
import random
@@ -1388,6 +1389,12 @@ class DecimalUsabilityTest(unittest.TestCase):
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)