Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
45fd4763
Commit
45fd4763
authored
Feb 03, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Register decimals as numbers.Number
parent
154ab71e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
0 deletions
+16
-0
Lib/decimal.py
Lib/decimal.py
+7
-0
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+7
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/decimal.py
View file @
45fd4763
...
...
@@ -135,6 +135,7 @@ __all__ = [
]
import
copy
as
_copy
import
numbers
as
_numbers
try
:
from
collections
import
namedtuple
as
_namedtuple
...
...
@@ -3567,6 +3568,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 #######################################################
...
...
Lib/test/test_decimal.py
View file @
45fd4763
...
...
@@ -30,6 +30,7 @@ import os, sys
import
pickle
,
copy
import
unittest
from
decimal
import
*
import
numbers
from
test.test_support
import
(
TestSkipped
,
run_unittest
,
run_doctest
,
is_resource_enabled
)
import
random
...
...
@@ -1334,6 +1335,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
)
...
...
Misc/NEWS
View file @
45fd4763
...
...
@@ -213,6 +213,8 @@ Library
- Issue #1885: distutils. When running sdist with --formats=tar,gztar
the tar file was overriden by the gztar one.
- Registered Decimal as a numbers.Number.
- Issue #1672332: fix unpickling of subnormal floats, which was
producing a ValueError on some platforms.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment