Index: Lib/test/pickletester.py =================================================================== --- Lib/test/pickletester.py (revision 82823) +++ Lib/test/pickletester.py (working copy) @@ -3,6 +3,7 @@ import cPickle import StringIO import pickletools +import math import copy_reg from test.test_support import TestFailed, have_unicode, TESTFN, \ @@ -548,7 +549,8 @@ def test_float(self): test_values = [0.0, 4.94e-324, 1e-310, 7e-308, 6.626e-34, 0.1, 0.5, - 3.14, 263.44582062374053, 6.022e23, 1e30] + 3.14, 263.44582062374053, 6.022e23, 1e30, + float('inf')] test_values = test_values + [-x for x in test_values] for proto in protocols: for value in test_values: @@ -556,6 +558,13 @@ got = self.loads(pickle) self.assertEqual(value, got) + def test_float_nan(self): + nan = float('nan') + for proto in protocols: + pickle = self.dumps(nan, proto) + got = self.loads(pickle) + self.assertTrue(math.isnan, got) + @run_with_locale('LC_ALL', 'de_DE', 'fr_FR') def test_float_format(self): # make sure that floats are formatted locale independent Index: Modules/cPickle.c =================================================================== --- Modules/cPickle.c (revision 82823) +++ Modules/cPickle.c (working copy) @@ -1172,7 +1172,7 @@ else { char c_str[250]; c_str[0] = FLOAT; - PyOS_ascii_formatd(c_str + 1, sizeof(c_str) - 2, "%.17g", x); + PyFloat_AsReprString(c_str + 1, (PyFloatObject *)args); /* Extend the formatted string with a newline character */ strcat(c_str, "\n");