Skip to content

Commit

Permalink
Merge 3.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
skrah committed Jun 20, 2016
2 parents df1d31c + 6817c59 commit 8113f49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2524,14 +2524,17 @@ def test_from_float(self):
Decimal = self.decimal.Decimal

class MyDecimal(Decimal):
pass
def __init__(self, _):
self.x = 'y'

self.assertTrue(issubclass(MyDecimal, Decimal))

r = MyDecimal.from_float(0.1)
self.assertEqual(type(r), MyDecimal)
self.assertEqual(str(r),
'0.1000000000000000055511151231257827021181583404541015625')
self.assertEqual(r.x, 'y')

bigint = 12345678901234567890123456789
self.assertEqual(MyDecimal.from_float(bigint), MyDecimal(bigint))
self.assertTrue(MyDecimal.from_float(float('nan')).is_qnan())
Expand Down
10 changes: 8 additions & 2 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,12 +2629,18 @@ PyDecType_FromSequenceExact(PyTypeObject *type, PyObject *v,

/* class method */
static PyObject *
dec_from_float(PyObject *dec, PyObject *pyfloat)
dec_from_float(PyObject *type, PyObject *pyfloat)
{
PyObject *context;
PyObject *result;

CURRENT_CONTEXT(context);
return PyDecType_FromFloatExact((PyTypeObject *)dec, pyfloat, context);
result = PyDecType_FromFloatExact(&PyDec_Type, pyfloat, context);
if (!PyDec_CheckExact(type) && result != NULL) {
Py_SETREF(result, PyObject_CallFunctionObjArgs(type, result, NULL));
}

return result;
}

/* create_decimal_from_float */
Expand Down

0 comments on commit 8113f49

Please sign in to comment.