[Python-checkins] r63948 - in python/trunk: Lib/test/test_complex.py Objects/complexobject.c

alexandre.vassalotti python-checkins at python.org
Wed Jun 4 22:41:44 CEST 2008


Author: alexandre.vassalotti
Date: Wed Jun 4 22:41:44 2008
New Revision: 63948
Log:
Fixed complex.__getnewargs__() to not emit another complex object.
Modified:
 python/trunk/Lib/test/test_complex.py
 python/trunk/Objects/complexobject.c
Modified: python/trunk/Lib/test/test_complex.py
==============================================================================
--- python/trunk/Lib/test/test_complex.py	(original)
+++ python/trunk/Lib/test/test_complex.py	Wed Jun 4 22:41:44 2008
@@ -373,6 +373,14 @@
 except (OSError, IOError):
 pass
 
+ def test_getnewargs(self):
+ self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))
+ self.assertEqual((1-2j).__getnewargs__(), (1.0, -2.0))
+ self.assertEqual((2j).__getnewargs__(), (0.0, 2.0))
+ self.assertEqual((-0j).__getnewargs__(), (0.0, -0.0))
+ self.assertEqual(complex(0, INF).__getnewargs__(), (0.0, INF))
+ self.assertEqual(complex(INF, 0).__getnewargs__(), (INF, 0.0))
+
 if float.__getformat__("double").startswith("IEEE"):
 def test_plus_minus_0j(self):
 # test that -0j and 0j literals are not identified
Modified: python/trunk/Objects/complexobject.c
==============================================================================
--- python/trunk/Objects/complexobject.c	(original)
+++ python/trunk/Objects/complexobject.c	Wed Jun 4 22:41:44 2008
@@ -822,7 +822,8 @@
 static PyObject *
 complex_getnewargs(PyComplexObject *v)
 {
-	return Py_BuildValue("(D)", &v->cval);
+	Py_complex c = v->cval;
+	return Py_BuildValue("(dd)", c.real, c.imag);
 }
 
 #if 0


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /