Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a0fd888

Browse files
committed
Issue 4998: Decimal should not subclass or register with numbers.Real.
1 parent 7bf3a0e commit a0fd888

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

Lib/decimal.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
'setcontext', 'getcontext', 'localcontext'
135135
]
136136

137-
import numbers as _numbers
138137
import copy as _copy
139138
import math as _math
140139

@@ -501,7 +500,11 @@ def sin(x):
501500

502501
##### Decimal class #######################################################
503502

504-
class Decimal(_numbers.Real):
503+
# Do not subclass Decimal from numbers.Real and do not register it as such
504+
# (because Decimals are not interoperable with floats). See the notes in
505+
# numbers.py for more detail.
506+
507+
class Decimal(object):
505508
"""Floating point class for decimal arithmetic."""
506509

507510
__slots__ = ('_exp','_int','_sign', '_is_special')
@@ -1757,14 +1760,10 @@ def __round__(self, n=None):
17571760
>>> round(Decimal('Inf'))
17581761
Traceback (most recent call last):
17591762
...
1760-
...
1761-
...
17621763
OverflowError: cannot round an infinity
17631764
>>> round(Decimal('NaN'))
17641765
Traceback (most recent call last):
17651766
...
1766-
...
1767-
...
17681767
ValueError: cannot round a NaN
17691768
17701769
If a second argument n is supplied, self is rounded to n
12 KB
Binary file not shown.

0 commit comments

Comments
 (0)