summaryrefslogtreecommitdiffstats
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-04-02 18:39:24 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-04-02 18:39:24 (GMT)
commited171abd93c7a507cb26339aa2d68a7e980378f6 (patch)
tree315daef20f38f289972e450f267b3576abdbce44 /Lib/decimal.py
parentdc36d7cf85b143995b8f0d3c0aaa35416d56a468 (diff)
downloadcpython-ed171abd93c7a507cb26339aa2d68a7e980378f6.zip
cpython-ed171abd93c7a507cb26339aa2d68a7e980378f6.tar.gz
cpython-ed171abd93c7a507cb26339aa2d68a7e980378f6.tar.bz2
Issue 8257: Decimal constructor to accept float.
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 34463ae..80ef20d 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)