Index: Lib/test/test_struct.py =================================================================== --- Lib/test/test_struct.py (Revision 70705) +++ Lib/test/test_struct.py (Arbeitskopie) @@ -11,12 +11,7 @@ IS32BIT = sys.maxsize == 0x7fffffff del sys -try: - import _struct -except ImportError: - PY_STRUCT_FLOAT_COERCE = 2 -else: - PY_STRUCT_FLOAT_COERCE = getattr(_struct, '_PY_STRUCT_FLOAT_COERCE', 0) +import _struct def string_reverse(s): return s[::-1] @@ -40,27 +35,6 @@ class StructTest(unittest.TestCase): - @with_warning_restore - def check_float_coerce(self, format, number): - # SF bug 1530559. struct.pack raises TypeError where it used to convert. - if PY_STRUCT_FLOAT_COERCE == 2: - # Test for pre-2.5 struct module - packed = struct.pack(format, number) - floored = struct.unpack(format, packed)[0] - self.assertEqual(floored, int(number), - "did not correcly coerce float to int") - return - try: - struct.pack(format, number) - except (struct.error, TypeError): - if PY_STRUCT_FLOAT_COERCE: - self.fail("expected DeprecationWarning for float coerce") - except DeprecationWarning: - if not PY_STRUCT_FLOAT_COERCE: - self.fail("expected to raise struct.error for float coerce") - else: - self.fail("did not raise error for float coerce") - def test_isbigendian(self): self.assertEqual((struct.pack('=i', 1)[0] == 0), ISBIGENDIAN) @@ -436,14 +410,6 @@ self.assertRaises((struct.error, OverflowError), struct.pack, endian + 'L', sys.maxsize * 4) - def XXXtest_1530559(self): - # XXX This is broken: see the bug report - # SF bug 1530559. struct.pack raises TypeError where it used to convert. - for endian in ('', '>', '<'): - for fmt in ('B', 'H', 'I', 'L', 'b', 'h', 'i', 'l'): - self.check_float_coerce(endian + fmt, 1.0) - self.check_float_coerce(endian + fmt, 1.5) - def test_unpack_from(self): test_string = b'abcd01234' fmt = '4s' Index: Modules/_struct.c =================================================================== --- Modules/_struct.c (Revision 70705) +++ Modules/_struct.c (Arbeitskopie) @@ -12,17 +12,6 @@ static PyTypeObject PyStructType; -/* If PY_STRUCT_FLOAT_COERCE is defined, the struct module will allow float - arguments for integer formats with a warning for backwards - compatibility. */ - -#define PY_STRUCT_FLOAT_COERCE 1 - -#ifdef PY_STRUCT_FLOAT_COERCE -#define FLOAT_COERCE "integer argument expected, got float" -#endif - - /* The translation function for each format character is table driven */ typedef struct _formatdef { char format; @@ -133,22 +122,8 @@ get_long(PyObject *v, long *p) { long x = PyLong_AsLong(v); + if (x == -1 && PyErr_Occurred()) { -#ifdef PY_STRUCT_FLOAT_COERCE - if (PyFloat_Check(v)) { - PyObject *o; - int res; - PyErr_Clear(); - if (PyErr_WarnEx(PyExc_DeprecationWarning, FLOAT_COERCE, 2) < 0) - return -1; - o = PyNumber_Long(v); - if (o == NULL) - return -1; - res = get_long(o, p); - Py_DECREF(o); - return res; - } -#endif if (PyErr_ExceptionMatches(PyExc_TypeError)) PyErr_SetString(StructError, "required argument is not an integer"); @@ -1962,7 +1937,7 @@ { PyObject *ver, *m; - ver = PyBytes_FromString("0.2"); + ver = PyBytes_FromString("0.3"); if (ver == NULL) return NULL; @@ -2028,9 +2003,5 @@ PyModule_AddObject(m, "__version__", ver); -#ifdef PY_STRUCT_FLOAT_COERCE - PyModule_AddIntConstant(m, "_PY_STRUCT_FLOAT_COERCE", 1); -#endif return m; - }