Merge 3.3.

This commit is contained in:
Stefan Krah 2012-11-08 11:19:55 +01:00
commit 4cb103ee39
2 changed files with 25 additions and 10 deletions

View File

@ -2029,7 +2029,7 @@ class UsabilityTest(unittest.TestCase):
Decimal = self.decimal.Decimal Decimal = self.decimal.Decimal
class MyDecimal(Decimal): class MyDecimal(Decimal):
pass y = None
d1 = MyDecimal(1) d1 = MyDecimal(1)
d2 = MyDecimal(2) d2 = MyDecimal(2)
@ -2047,14 +2047,29 @@ class UsabilityTest(unittest.TestCase):
self.assertIs(type(d), MyDecimal) self.assertIs(type(d), MyDecimal)
self.assertEqual(d, d1) self.assertEqual(d, d1)
a = Decimal('1.0') # Decimal(Decimal)
b = MyDecimal(a) d = Decimal('1.0')
self.assertIs(type(b), MyDecimal) x = Decimal(d)
self.assertEqual(a, b) self.assertIs(type(x), Decimal)
self.assertEqual(x, d)
c = Decimal(b) # MyDecimal(Decimal)
self.assertIs(type(c), Decimal) m = MyDecimal(d)
self.assertEqual(a, c) self.assertIs(type(m), MyDecimal)
self.assertEqual(m, d)
self.assertIs(m.y, None)
# Decimal(MyDecimal)
x = Decimal(m)
self.assertIs(type(x), Decimal)
self.assertEqual(x, d)
# MyDecimal(MyDecimal)
m.y = 9
x = MyDecimal(m)
self.assertIs(type(x), MyDecimal)
self.assertEqual(x, d)
self.assertIs(x.y, None)
def test_implicit_context(self): def test_implicit_context(self):
Decimal = self.decimal.Decimal Decimal = self.decimal.Decimal

View File

@ -2338,14 +2338,14 @@ PyDecType_FromFloat(PyTypeObject *type, PyObject *v,
return dec; return dec;
} }
/* Return a new PyDecObject (subtype) from a Decimal. */ /* Return a new PyDecObject or a subtype from a Decimal. */
static PyObject * static PyObject *
PyDecType_FromDecimalExact(PyTypeObject *type, PyObject *v, PyObject *context) PyDecType_FromDecimalExact(PyTypeObject *type, PyObject *v, PyObject *context)
{ {
PyObject *dec; PyObject *dec;
uint32_t status = 0; uint32_t status = 0;
if (type == Py_TYPE(v)) { if (type == &PyDec_Type && PyDec_CheckExact(v)) {
Py_INCREF(v); Py_INCREF(v);
return v; return v;
} }