| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dea9c86 commit f9bfbf3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,6 +136,7 @@ | |||
| 136 | 136 | ||
| 137 | 137 | import copy as _copy | |
| 138 | 138 | import math as _math | |
| 139 | + import numbers as _numbers | ||
| 139 | 140 | ||
| 140 | 141 | try: | |
| 141 | 142 | from collections import namedtuple as _namedtuple | |
@@ -3608,6 +3609,12 @@ def _dec_from_triple(sign, coefficient, exponent, special=False): | |||
| 3608 | 3609 | ||
| 3609 | 3610 | return self | |
| 3610 | 3611 | ||
| 3612 | + # Register Decimal as a kind of Number (an abstract base class). | ||
| 3613 | + # However, do not register it as Real (because Decimals are not | ||
| 3614 | + # interoperable with floats). | ||
| 3615 | + _numbers.Number.register(Decimal) | ||
| 3616 | + | ||
| 3617 | + | ||
| 3611 | 3618 | ##### Context class ####################################################### | |
| 3612 | 3619 | ||
| 3613 | 3620 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,7 @@ | |||
| 30 | 30 | import pickle, copy | |
| 31 | 31 | import unittest | |
| 32 | 32 | from decimal import * | |
| 33 | + import numbers | ||
| 33 | 34 | from test.test_support import (TestSkipped, run_unittest, run_doctest, | |
| 34 | 35 | is_resource_enabled) | |
| 35 | 36 | import random | |
@@ -1334,6 +1335,12 @@ def test_implicit_context(self): | |||
| 1334 | 1335 | ||
| 1335 | 1336 | class DecimalPythonAPItests(unittest.TestCase): | |
| 1336 | 1337 | ||
| 1338 | + def test_abc(self): | ||
| 1339 | + self.assert_(issubclass(Decimal, numbers.Number)) | ||
| 1340 | + self.assert_(not issubclass(Decimal, numbers.Real)) | ||
| 1341 | + self.assert_(isinstance(Decimal(0), numbers.Number)) | ||
| 1342 | + self.assert_(not isinstance(Decimal(0), numbers.Real)) | ||
| 1343 | + | ||
| 1337 | 1344 | def test_pickle(self): | |
| 1338 | 1345 | d = Decimal('-3.141590000') | |
| 1339 | 1346 | p = pickle.dumps(d) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments