[Python-checkins] cpython (merge 3.3 -> default): Merge 3.3.

stefan.krah python-checkins at python.org
Thu Nov 8 11:20:43 CET 2012


http://hg.python.org/cpython/rev/b59f021a71c7
changeset:   80312:b59f021a71c7
parent:      80310:6eba4df6bb21
parent:      80311:9a701e8ec2c9
user:        Stefan Krah <skrah at bytereef.org>
date:        Thu Nov 08 11:19:55 2012 +0100
summary:
  Merge 3.3.

files:
  Lib/test/test_decimal.py    |  33 ++++++++++++++++++------
  Modules/_decimal/_decimal.c |   4 +-
  2 files changed, 26 insertions(+), 11 deletions(-)


diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -2029,7 +2029,7 @@
         Decimal = self.decimal.Decimal
 
         class MyDecimal(Decimal):
-            pass
+            y = None
 
         d1 = MyDecimal(1)
         d2 = MyDecimal(2)
@@ -2047,14 +2047,29 @@
         self.assertIs(type(d), MyDecimal)
         self.assertEqual(d, d1)
 
-        a = Decimal('1.0')
-        b = MyDecimal(a)
-        self.assertIs(type(b), MyDecimal)
-        self.assertEqual(a, b)
-
-        c = Decimal(b)
-        self.assertIs(type(c), Decimal)
-        self.assertEqual(a, c)
+        # Decimal(Decimal)
+        d = Decimal('1.0')
+        x = Decimal(d)
+        self.assertIs(type(x), Decimal)
+        self.assertEqual(x, d)
+
+        # MyDecimal(Decimal)
+        m = MyDecimal(d)
+        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):
         Decimal = self.decimal.Decimal
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -2338,14 +2338,14 @@
     return dec;
 }
 
-/* Return a new PyDecObject (subtype) from a Decimal. */
+/* Return a new PyDecObject or a subtype from a Decimal. */
 static PyObject *
 PyDecType_FromDecimalExact(PyTypeObject *type, PyObject *v, PyObject *context)
 {
     PyObject *dec;
     uint32_t status = 0;
 
-    if (type == Py_TYPE(v)) {
+    if (type == &PyDec_Type && PyDec_CheckExact(v)) {
         Py_INCREF(v);
         return v;
     }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list