mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Merge 3.5.
This commit is contained in:
commit
8113f490c5
2 changed files with 12 additions and 3 deletions
|
@ -2524,7 +2524,8 @@ class PythonAPItests(unittest.TestCase):
|
||||||
Decimal = self.decimal.Decimal
|
Decimal = self.decimal.Decimal
|
||||||
|
|
||||||
class MyDecimal(Decimal):
|
class MyDecimal(Decimal):
|
||||||
pass
|
def __init__(self, _):
|
||||||
|
self.x = 'y'
|
||||||
|
|
||||||
self.assertTrue(issubclass(MyDecimal, Decimal))
|
self.assertTrue(issubclass(MyDecimal, Decimal))
|
||||||
|
|
||||||
|
@ -2532,6 +2533,8 @@ class PythonAPItests(unittest.TestCase):
|
||||||
self.assertEqual(type(r), MyDecimal)
|
self.assertEqual(type(r), MyDecimal)
|
||||||
self.assertEqual(str(r),
|
self.assertEqual(str(r),
|
||||||
'0.1000000000000000055511151231257827021181583404541015625')
|
'0.1000000000000000055511151231257827021181583404541015625')
|
||||||
|
self.assertEqual(r.x, 'y')
|
||||||
|
|
||||||
bigint = 12345678901234567890123456789
|
bigint = 12345678901234567890123456789
|
||||||
self.assertEqual(MyDecimal.from_float(bigint), MyDecimal(bigint))
|
self.assertEqual(MyDecimal.from_float(bigint), MyDecimal(bigint))
|
||||||
self.assertTrue(MyDecimal.from_float(float('nan')).is_qnan())
|
self.assertTrue(MyDecimal.from_float(float('nan')).is_qnan())
|
||||||
|
|
|
@ -2629,12 +2629,18 @@ PyDecType_FromSequenceExact(PyTypeObject *type, PyObject *v,
|
||||||
|
|
||||||
/* class method */
|
/* class method */
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dec_from_float(PyObject *dec, PyObject *pyfloat)
|
dec_from_float(PyObject *type, PyObject *pyfloat)
|
||||||
{
|
{
|
||||||
PyObject *context;
|
PyObject *context;
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
CURRENT_CONTEXT(context);
|
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 */
|
/* create_decimal_from_float */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue