From: Christian Heimes Date: Tue, 15 Jan 2008 02:01:20 +0000 (+0000) Subject: long(float('nan')) raises an OverflowError as discussed on the mailing list a week ago X-Git-Tag: v3.0a3~199 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=386cd1e3c950b038fefefbf5ad887fd7f3215dc8;p=python long(float('nan')) raises an OverflowError as discussed on the mailing list a week ago --- diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 09adc74991..18bb7a4595 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -539,7 +539,7 @@ class LongTest(unittest.TestCase): def test_nan_inf(self): self.assertRaises(OverflowError, int, float('inf')) - self.assertEqual(int(float('nan')), 0) + self.assertRaises(OverflowError, int, float('nan')) def test_main(): test_support.run_unittest(LongTest) diff --git a/Misc/NEWS b/Misc/NEWS index 8a770609ba..c59efa1b43 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 3.0a3? Core and Builtins ----------------- +- Object/longobject.c: long(float('nan')) raises an OverflowError instead + of returning 0. + - Issue #1762972: __file__ points to the source file instead of the pyc/pyo file if the py file exists. diff --git a/Objects/longobject.c b/Objects/longobject.c index dc7ce87afc..4b7eee059c 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -255,7 +255,9 @@ PyLong_FromDouble(double dval) return NULL; } if (Py_IS_NAN(dval)) { - return PyLong_FromLong(0L); + PyErr_SetString(PyExc_OverflowError, + "cannot convert float NaN to int"); + return NULL; } if (dval < 0.0) { neg = 1;