Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c885443

Browse files
committed
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.
1 parent 1fa040b commit c885443

8 files changed

Lines changed: 25 additions & 45 deletions

File tree

Doc/lib/libexcs.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ \section{Built-in Exceptions}
460460
+-- DeprecationWarning
461461
+-- PendingDeprecationWarning
462462
+-- SyntaxWarning
463-
+-- OverflowWarning
463+
+-- OverflowWarning (not generated in 2.4; won't exist in 2.5)
464464
+-- RuntimeWarning
465465
+-- FutureWarning
466466
\end{verbatim}

Include/pyerrors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ PyAPI_DATA(PyObject *) PyExc_UserWarning;
7474
PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
7575
PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
7676
PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
77+
/* PyExc_OverflowWarning will go away for Python 2.5 */
7778
PyAPI_DATA(PyObject *) PyExc_OverflowWarning;
7879
PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
7980
PyAPI_DATA(PyObject *) PyExc_FutureWarning;

Lib/test/test_exceptions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,16 @@ def r(thing):
8585

8686
r(OverflowError)
8787
# XXX
88-
# Obscure: this test relies on int+int raising OverflowError if the
89-
# ints are big enough. But ints no longer do that by default. This
90-
# test will have to go away someday. For now, we can convert the
91-
# transitional OverflowWarning into an error.
88+
# Obscure: in 2.2 and 2.3, this test relied on changing OverflowWarning
89+
# into an error, in order to trigger OverflowError. In 2.4, OverflowWarning
90+
# should no longer be generated, so the focus of the test shifts to showing
91+
# that OverflowError *isn't* generated. OverflowWarning should be gone
92+
# in Python 2.5, and then the filterwarnings() call, and this comment,
93+
# should go away.
9294
warnings.filterwarnings("error", "", OverflowWarning, __name__)
9395
x = 1
94-
try:
95-
while 1: x = x+x
96-
except OverflowError: pass
96+
for dummy in range(128):
97+
x += x # this simply shouldn't blow up
9798

9899
r(RuntimeError)
99100
print '(not used any more?)'

Lib/test/test_warnings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_warn_default_category(self):
4444

4545
def test_warn_specific_category(self):
4646
text = 'None'
47+
# XXX OverflowWarning should go away for Python 2.5.
4748
for category in [DeprecationWarning, FutureWarning, OverflowWarning,
4849
PendingDeprecationWarning, RuntimeWarning,
4950
SyntaxWarning, UserWarning, Warning]:

Lib/warnings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,6 @@ def _getcategory(category):
250250

251251
# Module initialization
252252
_processoptions(sys.warnoptions)
253+
# XXX OverflowWarning should go away for Python 2.5.
253254
simplefilter("ignore", category=OverflowWarning, append=1)
254255
simplefilter("ignore", category=PendingDeprecationWarning, append=1)

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ What's New in Python 2.4 alpha 3?
1212
Core and builtins
1313
-----------------
1414

15+
- OverflowWarning is no longer generated. PEP 237 scheduled this to
16+
occur in Python 2.3, but since OverflowWarning was disabled by default,
17+
nobody realized it was still being generated. On the chance that user
18+
code is still using them, the Python builtin OverflowWarning, and
19+
corresponding C API PyExc_OverflowWarning, will exist until Python 2.5.
20+
1521
- Py_InitializeEx has been added.
1622

1723
- Fix the order of application of decorators. The proper order is bottom-up;

Objects/intobject.c

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ PyInt_GetMax(void)
1010
return LONG_MAX; /* To initialize sys.maxint */
1111
}
1212

13-
/* Return 1 if exception raised, 0 if caller should retry using longs */
14-
static int
15-
err_ovf(char *msg)
16-
{
17-
if (PyErr_Warn(PyExc_OverflowWarning, msg) < 0) {
18-
if (PyErr_ExceptionMatches(PyExc_OverflowWarning))
19-
PyErr_SetString(PyExc_OverflowError, msg);
20-
return 1;
21-
}
22-
else
23-
return 0;
24-
}
25-
2613
/* Integers are quite normal objects, to make object handling uniform.
2714
(Using odd pointers to represent integers would save much space
2815
but require extra checks for this special case throughout the code.)
@@ -306,11 +293,8 @@ PyInt_FromString(char *s, char **pend, int base)
306293
PyErr_SetString(PyExc_ValueError, buffer);
307294
return NULL;
308295
}
309-
else if (errno != 0) {
310-
if (err_ovf("string/unicode conversion"))
311-
return NULL;
296+
else if (errno != 0)
312297
return PyLong_FromString(s, pend, base);
313-
}
314298
if (pend)
315299
*pend = end;
316300
return PyInt_FromLong(x);
@@ -396,8 +380,6 @@ int_add(PyIntObject *v, PyIntObject *w)
396380
x = a + b;
397381
if ((x^a) >= 0 || (x^b) >= 0)
398382
return PyInt_FromLong(x);
399-
if (err_ovf("integer addition"))
400-
return NULL;
401383
return PyLong_Type.tp_as_number->nb_add((PyObject *)v, (PyObject *)w);
402384
}
403385

@@ -410,8 +392,6 @@ int_sub(PyIntObject *v, PyIntObject *w)
410392
x = a - b;
411393
if ((x^a) >= 0 || (x^~b) >= 0)
412394
return PyInt_FromLong(x);
413-
if (err_ovf("integer subtraction"))
414-
return NULL;
415395
return PyLong_Type.tp_as_number->nb_subtract((PyObject *)v,
416396
(PyObject *)w);
417397
}
@@ -475,8 +455,6 @@ int_mul(PyObject *v, PyObject *w)
475455
32 * absdiff <= absprod -- 5 good bits is "close enough" */
476456
if (32.0 * absdiff <= absprod)
477457
return PyInt_FromLong(longprod);
478-
else if (err_ovf("integer multiplication"))
479-
return NULL;
480458
else
481459
return PyLong_Type.tp_as_number->nb_multiply(v, w);
482460
}
@@ -501,11 +479,8 @@ i_divmod(register long x, register long y,
501479
return DIVMOD_ERROR;
502480
}
503481
/* (-sys.maxint-1)/-1 is the only overflow case. */
504-
if (y == -1 && x < 0 && x == -x) {
505-
if (err_ovf("integer division"))
506-
return DIVMOD_ERROR;
482+
if (y == -1 && x < 0 && x == -x)
507483
return DIVMOD_OVERFLOW;
508-
}
509484
xdivy = x / y;
510485
xmody = x - xdivy * y;
511486
/* 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)
654629
if (temp == 0)
655630
break; /* Avoid ix / 0 */
656631
if (ix / temp != prev) {
657-
if (err_ovf("integer exponentiation"))
658-
return NULL;
659632
return PyLong_Type.tp_as_number->nb_power(
660633
(PyObject *)v,
661634
(PyObject *)w,
@@ -666,9 +639,7 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
666639
if (iw==0) break;
667640
prev = temp;
668641
temp *= temp; /* Square the value of temp */
669-
if (prev!=0 && temp/prev!=prev) {
670-
if (err_ovf("integer exponentiation"))
671-
return NULL;
642+
if (prev != 0 && temp / prev != prev) {
672643
return PyLong_Type.tp_as_number->nb_power(
673644
(PyObject *)v, (PyObject *)w, (PyObject *)z);
674645
}
@@ -701,10 +672,7 @@ int_neg(PyIntObject *v)
701672
a = v->ob_ival;
702673
x = -a;
703674
if (a < 0 && x < 0) {
704-
PyObject *o;
705-
if (err_ovf("integer negation"))
706-
return NULL;
707-
o = PyLong_FromLong(a);
675+
PyObject *o = PyLong_FromLong(a);
708676
if (o != NULL) {
709677
PyObject *result = PyNumber_Negative(o);
710678
Py_DECREF(o);

Python/exceptions.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ PyDoc_STRVAR(SyntaxWarning__doc__,
15601560
"Base class for warnings about dubious syntax.");
15611561

15621562
PyDoc_STRVAR(OverflowWarning__doc__,
1563-
"Base class for warnings about numeric overflow.");
1563+
"Base class for warnings about numeric overflow. Won't exist in Python 2.5.");
15641564

15651565
PyDoc_STRVAR(RuntimeWarning__doc__,
15661566
"Base class for warnings about dubious runtime behavior.");
@@ -1635,6 +1635,7 @@ PyObject *PyExc_UserWarning;
16351635
PyObject *PyExc_DeprecationWarning;
16361636
PyObject *PyExc_PendingDeprecationWarning;
16371637
PyObject *PyExc_SyntaxWarning;
1638+
/* PyExc_OverflowWarning should be removed for Python 2.5 */
16381639
PyObject *PyExc_OverflowWarning;
16391640
PyObject *PyExc_RuntimeWarning;
16401641
PyObject *PyExc_FutureWarning;
@@ -1726,6 +1727,7 @@ static struct {
17261727
{"PendingDeprecationWarning", &PyExc_PendingDeprecationWarning, &PyExc_Warning,
17271728
PendingDeprecationWarning__doc__},
17281729
{"SyntaxWarning", &PyExc_SyntaxWarning, &PyExc_Warning, SyntaxWarning__doc__},
1730+
/* OverflowWarning should be removed for Python 2.5 */
17291731
{"OverflowWarning", &PyExc_OverflowWarning, &PyExc_Warning,
17301732
OverflowWarning__doc__},
17311733
{"RuntimeWarning", &PyExc_RuntimeWarning, &PyExc_Warning,

0 commit comments

Comments
 (0)