mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Stop producing or using OverflowWarning. PEP 237 thought this would
happen in 2.3, but nobody noticed it still was getting generated (the warning was disabled by default). OverflowWarning and PyExc_OverflowWarning should be removed for 2.5, and left notes all over saying so.
This commit is contained in:
parent
1fa040ba73
commit
c885443479
8 changed files with 25 additions and 45 deletions
|
@ -460,7 +460,7 @@ The class hierarchy for built-in exceptions is:
|
||||||
+-- DeprecationWarning
|
+-- DeprecationWarning
|
||||||
+-- PendingDeprecationWarning
|
+-- PendingDeprecationWarning
|
||||||
+-- SyntaxWarning
|
+-- SyntaxWarning
|
||||||
+-- OverflowWarning
|
+-- OverflowWarning (not generated in 2.4; won't exist in 2.5)
|
||||||
+-- RuntimeWarning
|
+-- RuntimeWarning
|
||||||
+-- FutureWarning
|
+-- FutureWarning
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
|
@ -74,6 +74,7 @@ PyAPI_DATA(PyObject *) PyExc_UserWarning;
|
||||||
PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
|
PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
|
||||||
PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
|
PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
|
||||||
PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
|
PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
|
||||||
|
/* PyExc_OverflowWarning will go away for Python 2.5 */
|
||||||
PyAPI_DATA(PyObject *) PyExc_OverflowWarning;
|
PyAPI_DATA(PyObject *) PyExc_OverflowWarning;
|
||||||
PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
|
PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
|
||||||
PyAPI_DATA(PyObject *) PyExc_FutureWarning;
|
PyAPI_DATA(PyObject *) PyExc_FutureWarning;
|
||||||
|
|
|
@ -85,15 +85,16 @@ except NameError: pass
|
||||||
|
|
||||||
r(OverflowError)
|
r(OverflowError)
|
||||||
# XXX
|
# XXX
|
||||||
# Obscure: this test relies on int+int raising OverflowError if the
|
# Obscure: in 2.2 and 2.3, this test relied on changing OverflowWarning
|
||||||
# ints are big enough. But ints no longer do that by default. This
|
# into an error, in order to trigger OverflowError. In 2.4, OverflowWarning
|
||||||
# test will have to go away someday. For now, we can convert the
|
# should no longer be generated, so the focus of the test shifts to showing
|
||||||
# transitional OverflowWarning into an error.
|
# that OverflowError *isn't* generated. OverflowWarning should be gone
|
||||||
|
# in Python 2.5, and then the filterwarnings() call, and this comment,
|
||||||
|
# should go away.
|
||||||
warnings.filterwarnings("error", "", OverflowWarning, __name__)
|
warnings.filterwarnings("error", "", OverflowWarning, __name__)
|
||||||
x = 1
|
x = 1
|
||||||
try:
|
for dummy in range(128):
|
||||||
while 1: x = x+x
|
x += x # this simply shouldn't blow up
|
||||||
except OverflowError: pass
|
|
||||||
|
|
||||||
r(RuntimeError)
|
r(RuntimeError)
|
||||||
print '(not used any more?)'
|
print '(not used any more?)'
|
||||||
|
|
|
@ -44,6 +44,7 @@ class TestModule(unittest.TestCase):
|
||||||
|
|
||||||
def test_warn_specific_category(self):
|
def test_warn_specific_category(self):
|
||||||
text = 'None'
|
text = 'None'
|
||||||
|
# XXX OverflowWarning should go away for Python 2.5.
|
||||||
for category in [DeprecationWarning, FutureWarning, OverflowWarning,
|
for category in [DeprecationWarning, FutureWarning, OverflowWarning,
|
||||||
PendingDeprecationWarning, RuntimeWarning,
|
PendingDeprecationWarning, RuntimeWarning,
|
||||||
SyntaxWarning, UserWarning, Warning]:
|
SyntaxWarning, UserWarning, Warning]:
|
||||||
|
|
|
@ -250,5 +250,6 @@ def _getcategory(category):
|
||||||
|
|
||||||
# Module initialization
|
# Module initialization
|
||||||
_processoptions(sys.warnoptions)
|
_processoptions(sys.warnoptions)
|
||||||
|
# XXX OverflowWarning should go away for Python 2.5.
|
||||||
simplefilter("ignore", category=OverflowWarning, append=1)
|
simplefilter("ignore", category=OverflowWarning, append=1)
|
||||||
simplefilter("ignore", category=PendingDeprecationWarning, append=1)
|
simplefilter("ignore", category=PendingDeprecationWarning, append=1)
|
||||||
|
|
|
@ -12,6 +12,12 @@ What's New in Python 2.4 alpha 3?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- OverflowWarning is no longer generated. PEP 237 scheduled this to
|
||||||
|
occur in Python 2.3, but since OverflowWarning was disabled by default,
|
||||||
|
nobody realized it was still being generated. On the chance that user
|
||||||
|
code is still using them, the Python builtin OverflowWarning, and
|
||||||
|
corresponding C API PyExc_OverflowWarning, will exist until Python 2.5.
|
||||||
|
|
||||||
- Py_InitializeEx has been added.
|
- Py_InitializeEx has been added.
|
||||||
|
|
||||||
- Fix the order of application of decorators. The proper order is bottom-up;
|
- Fix the order of application of decorators. The proper order is bottom-up;
|
||||||
|
|
|
@ -10,19 +10,6 @@ PyInt_GetMax(void)
|
||||||
return LONG_MAX; /* To initialize sys.maxint */
|
return LONG_MAX; /* To initialize sys.maxint */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return 1 if exception raised, 0 if caller should retry using longs */
|
|
||||||
static int
|
|
||||||
err_ovf(char *msg)
|
|
||||||
{
|
|
||||||
if (PyErr_Warn(PyExc_OverflowWarning, msg) < 0) {
|
|
||||||
if (PyErr_ExceptionMatches(PyExc_OverflowWarning))
|
|
||||||
PyErr_SetString(PyExc_OverflowError, msg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Integers are quite normal objects, to make object handling uniform.
|
/* Integers are quite normal objects, to make object handling uniform.
|
||||||
(Using odd pointers to represent integers would save much space
|
(Using odd pointers to represent integers would save much space
|
||||||
but require extra checks for this special case throughout the code.)
|
but require extra checks for this special case throughout the code.)
|
||||||
|
@ -306,11 +293,8 @@ PyInt_FromString(char *s, char **pend, int base)
|
||||||
PyErr_SetString(PyExc_ValueError, buffer);
|
PyErr_SetString(PyExc_ValueError, buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (errno != 0) {
|
else if (errno != 0)
|
||||||
if (err_ovf("string/unicode conversion"))
|
|
||||||
return NULL;
|
|
||||||
return PyLong_FromString(s, pend, base);
|
return PyLong_FromString(s, pend, base);
|
||||||
}
|
|
||||||
if (pend)
|
if (pend)
|
||||||
*pend = end;
|
*pend = end;
|
||||||
return PyInt_FromLong(x);
|
return PyInt_FromLong(x);
|
||||||
|
@ -396,8 +380,6 @@ int_add(PyIntObject *v, PyIntObject *w)
|
||||||
x = a + b;
|
x = a + b;
|
||||||
if ((x^a) >= 0 || (x^b) >= 0)
|
if ((x^a) >= 0 || (x^b) >= 0)
|
||||||
return PyInt_FromLong(x);
|
return PyInt_FromLong(x);
|
||||||
if (err_ovf("integer addition"))
|
|
||||||
return NULL;
|
|
||||||
return PyLong_Type.tp_as_number->nb_add((PyObject *)v, (PyObject *)w);
|
return PyLong_Type.tp_as_number->nb_add((PyObject *)v, (PyObject *)w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,8 +392,6 @@ int_sub(PyIntObject *v, PyIntObject *w)
|
||||||
x = a - b;
|
x = a - b;
|
||||||
if ((x^a) >= 0 || (x^~b) >= 0)
|
if ((x^a) >= 0 || (x^~b) >= 0)
|
||||||
return PyInt_FromLong(x);
|
return PyInt_FromLong(x);
|
||||||
if (err_ovf("integer subtraction"))
|
|
||||||
return NULL;
|
|
||||||
return PyLong_Type.tp_as_number->nb_subtract((PyObject *)v,
|
return PyLong_Type.tp_as_number->nb_subtract((PyObject *)v,
|
||||||
(PyObject *)w);
|
(PyObject *)w);
|
||||||
}
|
}
|
||||||
|
@ -475,8 +455,6 @@ int_mul(PyObject *v, PyObject *w)
|
||||||
32 * absdiff <= absprod -- 5 good bits is "close enough" */
|
32 * absdiff <= absprod -- 5 good bits is "close enough" */
|
||||||
if (32.0 * absdiff <= absprod)
|
if (32.0 * absdiff <= absprod)
|
||||||
return PyInt_FromLong(longprod);
|
return PyInt_FromLong(longprod);
|
||||||
else if (err_ovf("integer multiplication"))
|
|
||||||
return NULL;
|
|
||||||
else
|
else
|
||||||
return PyLong_Type.tp_as_number->nb_multiply(v, w);
|
return PyLong_Type.tp_as_number->nb_multiply(v, w);
|
||||||
}
|
}
|
||||||
|
@ -501,11 +479,8 @@ i_divmod(register long x, register long y,
|
||||||
return DIVMOD_ERROR;
|
return DIVMOD_ERROR;
|
||||||
}
|
}
|
||||||
/* (-sys.maxint-1)/-1 is the only overflow case. */
|
/* (-sys.maxint-1)/-1 is the only overflow case. */
|
||||||
if (y == -1 && x < 0 && x == -x) {
|
if (y == -1 && x < 0 && x == -x)
|
||||||
if (err_ovf("integer division"))
|
|
||||||
return DIVMOD_ERROR;
|
|
||||||
return DIVMOD_OVERFLOW;
|
return DIVMOD_OVERFLOW;
|
||||||
}
|
|
||||||
xdivy = x / y;
|
xdivy = x / y;
|
||||||
xmody = x - xdivy * y;
|
xmody = x - xdivy * y;
|
||||||
/* If the signs of x and y differ, and the remainder is non-0,
|
/* If the signs of x and y differ, and the remainder is non-0,
|
||||||
|
@ -654,8 +629,6 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
|
||||||
if (temp == 0)
|
if (temp == 0)
|
||||||
break; /* Avoid ix / 0 */
|
break; /* Avoid ix / 0 */
|
||||||
if (ix / temp != prev) {
|
if (ix / temp != prev) {
|
||||||
if (err_ovf("integer exponentiation"))
|
|
||||||
return NULL;
|
|
||||||
return PyLong_Type.tp_as_number->nb_power(
|
return PyLong_Type.tp_as_number->nb_power(
|
||||||
(PyObject *)v,
|
(PyObject *)v,
|
||||||
(PyObject *)w,
|
(PyObject *)w,
|
||||||
|
@ -666,9 +639,7 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
|
||||||
if (iw==0) break;
|
if (iw==0) break;
|
||||||
prev = temp;
|
prev = temp;
|
||||||
temp *= temp; /* Square the value of temp */
|
temp *= temp; /* Square the value of temp */
|
||||||
if (prev!=0 && temp/prev!=prev) {
|
if (prev != 0 && temp / prev != prev) {
|
||||||
if (err_ovf("integer exponentiation"))
|
|
||||||
return NULL;
|
|
||||||
return PyLong_Type.tp_as_number->nb_power(
|
return PyLong_Type.tp_as_number->nb_power(
|
||||||
(PyObject *)v, (PyObject *)w, (PyObject *)z);
|
(PyObject *)v, (PyObject *)w, (PyObject *)z);
|
||||||
}
|
}
|
||||||
|
@ -701,10 +672,7 @@ int_neg(PyIntObject *v)
|
||||||
a = v->ob_ival;
|
a = v->ob_ival;
|
||||||
x = -a;
|
x = -a;
|
||||||
if (a < 0 && x < 0) {
|
if (a < 0 && x < 0) {
|
||||||
PyObject *o;
|
PyObject *o = PyLong_FromLong(a);
|
||||||
if (err_ovf("integer negation"))
|
|
||||||
return NULL;
|
|
||||||
o = PyLong_FromLong(a);
|
|
||||||
if (o != NULL) {
|
if (o != NULL) {
|
||||||
PyObject *result = PyNumber_Negative(o);
|
PyObject *result = PyNumber_Negative(o);
|
||||||
Py_DECREF(o);
|
Py_DECREF(o);
|
||||||
|
|
|
@ -1560,7 +1560,7 @@ PyDoc_STRVAR(SyntaxWarning__doc__,
|
||||||
"Base class for warnings about dubious syntax.");
|
"Base class for warnings about dubious syntax.");
|
||||||
|
|
||||||
PyDoc_STRVAR(OverflowWarning__doc__,
|
PyDoc_STRVAR(OverflowWarning__doc__,
|
||||||
"Base class for warnings about numeric overflow.");
|
"Base class for warnings about numeric overflow. Won't exist in Python 2.5.");
|
||||||
|
|
||||||
PyDoc_STRVAR(RuntimeWarning__doc__,
|
PyDoc_STRVAR(RuntimeWarning__doc__,
|
||||||
"Base class for warnings about dubious runtime behavior.");
|
"Base class for warnings about dubious runtime behavior.");
|
||||||
|
@ -1635,6 +1635,7 @@ PyObject *PyExc_UserWarning;
|
||||||
PyObject *PyExc_DeprecationWarning;
|
PyObject *PyExc_DeprecationWarning;
|
||||||
PyObject *PyExc_PendingDeprecationWarning;
|
PyObject *PyExc_PendingDeprecationWarning;
|
||||||
PyObject *PyExc_SyntaxWarning;
|
PyObject *PyExc_SyntaxWarning;
|
||||||
|
/* PyExc_OverflowWarning should be removed for Python 2.5 */
|
||||||
PyObject *PyExc_OverflowWarning;
|
PyObject *PyExc_OverflowWarning;
|
||||||
PyObject *PyExc_RuntimeWarning;
|
PyObject *PyExc_RuntimeWarning;
|
||||||
PyObject *PyExc_FutureWarning;
|
PyObject *PyExc_FutureWarning;
|
||||||
|
@ -1726,6 +1727,7 @@ static struct {
|
||||||
{"PendingDeprecationWarning", &PyExc_PendingDeprecationWarning, &PyExc_Warning,
|
{"PendingDeprecationWarning", &PyExc_PendingDeprecationWarning, &PyExc_Warning,
|
||||||
PendingDeprecationWarning__doc__},
|
PendingDeprecationWarning__doc__},
|
||||||
{"SyntaxWarning", &PyExc_SyntaxWarning, &PyExc_Warning, SyntaxWarning__doc__},
|
{"SyntaxWarning", &PyExc_SyntaxWarning, &PyExc_Warning, SyntaxWarning__doc__},
|
||||||
|
/* OverflowWarning should be removed for Python 2.5 */
|
||||||
{"OverflowWarning", &PyExc_OverflowWarning, &PyExc_Warning,
|
{"OverflowWarning", &PyExc_OverflowWarning, &PyExc_Warning,
|
||||||
OverflowWarning__doc__},
|
OverflowWarning__doc__},
|
||||||
{"RuntimeWarning", &PyExc_RuntimeWarning, &PyExc_Warning,
|
{"RuntimeWarning", &PyExc_RuntimeWarning, &PyExc_Warning,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue