summaryrefslogtreecommitdiff
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-04-02 16:58:27 +0000
committerRaymond Hettinger <python@rcn.com>2010-04-02 16:58:27 +0000
commitfa3fdcc4823cb64ef7d4338b4701c77a4d10d9f6 (patch)
treebe4ed42f1574fdcbcf04ca8e44c3ca393219a92f /Lib/decimal.py
parent0459c56c2a029d8c967be04911bef8a5e4fddfca (diff)
downloadcpython-fa3fdcc4823cb64ef7d4338b4701c77a4d10d9f6.tar.gz
Issue 8257: Decimal constructor to accept float argument.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 370eb821ba..ab38ed4ef0 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -648,8 +648,12 @@ class Decimal(object):
return self
if isinstance(value, float):
- raise TypeError("Cannot convert float in Decimal constructor. "
- "Use from_float class method.")
+ value = Decimal.from_float(value)
+ self._exp = value._exp
+ self._sign = value._sign
+ self._int = value._int
+ self._is_special = value._is_special
+ return self
raise TypeError("Cannot convert %r to Decimal" % value)