mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Have Decimal.as_tuple return a named tuple.
This commit is contained in:
parent
a7d984e838
commit
097a190303
1 changed files with 7 additions and 1 deletions
|
@ -136,6 +136,12 @@ __all__ = [
|
||||||
|
|
||||||
import copy as _copy
|
import copy as _copy
|
||||||
|
|
||||||
|
try:
|
||||||
|
from collections import namedtuple as _namedtuple
|
||||||
|
DecimalTuple = _namedtuple('DecimalTuple', 'sign digits exponent')
|
||||||
|
except ImportError:
|
||||||
|
DecimalTuple = lambda *args: args
|
||||||
|
|
||||||
# Rounding
|
# Rounding
|
||||||
ROUND_DOWN = 'ROUND_DOWN'
|
ROUND_DOWN = 'ROUND_DOWN'
|
||||||
ROUND_HALF_UP = 'ROUND_HALF_UP'
|
ROUND_HALF_UP = 'ROUND_HALF_UP'
|
||||||
|
@ -820,7 +826,7 @@ class Decimal(object):
|
||||||
|
|
||||||
To show the internals exactly as they are.
|
To show the internals exactly as they are.
|
||||||
"""
|
"""
|
||||||
return (self._sign, tuple(map(int, self._int)), self._exp)
|
return DecimalTuple(self._sign, tuple(map(int, self._int)), self._exp)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Represents the number as an instance of Decimal."""
|
"""Represents the number as an instance of Decimal."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue