[Python-checkins] r61475 - in python/trunk: Misc/ACKS Misc/NEWS Python/ceval.c
guido.van.rossum
python-checkins at python.org
Tue Mar 18 03:49:47 CET 2008
Author: guido.van.rossum
Date: Tue Mar 18 03:49:46 2008
New Revision: 61475
Modified:
python/trunk/Misc/ACKS
python/trunk/Misc/NEWS
python/trunk/Python/ceval.c
Log:
- Issue #2371: Add a Py3k warning when catching an exception that
doesn't derive from BaseException.
Modified: python/trunk/Misc/ACKS
==============================================================================
--- python/trunk/Misc/ACKS (original)
+++ python/trunk/Misc/ACKS Tue Mar 18 03:49:46 2008
@@ -360,6 +360,7 @@
Lawrence Kesteloot
Vivek Khera
Mads Kiilerich
+Taek Joo Kim
Steve Kirsch
Ron Klatchko
Bastian Kleineidam
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Tue Mar 18 03:49:46 2008
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- Issue #2371: Add a Py3k warning when catching an exception that
+ doesn't derive from BaseException.
+
- Issue #2321: use pymalloc for unicode object string data to reduce
memory usage in some circumstances.
Modified: python/trunk/Python/ceval.c
==============================================================================
--- python/trunk/Python/ceval.c (original)
+++ python/trunk/Python/ceval.c Tue Mar 18 03:49:46 2008
@@ -4042,6 +4042,13 @@
}
}
+#define Py3kExceptionClass_Check(x) \
+ (PyType_Check((x)) && \
+ PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
+
+#define CANNOT_CATCH_MSG "catching classes that don't inherit from " \
+ "BaseException is not allowed in 3.x."
+
static PyObject *
cmp_outcome(int op, register PyObject *v, register PyObject *w)
{
@@ -4079,6 +4086,16 @@
if (ret_val == -1)
return NULL;
}
+ if (Py_Py3kWarningFlag &&
+ !Py3kExceptionClass_Check(exc))
+ {
+ int ret_val;
+ ret_val = PyErr_WarnEx(
+ PyExc_DeprecationWarning,
+ CANNOT_CATCH_MSG, 1);
+ if (ret_val == -1)
+ return NULL;
+ }
}
}
else {
@@ -4091,6 +4108,16 @@
if (ret_val == -1)
return NULL;
}
+ if (Py_Py3kWarningFlag &&
+ !Py3kExceptionClass_Check(w))
+ {
+ int ret_val;
+ ret_val = PyErr_WarnEx(
+ PyExc_DeprecationWarning,
+ CANNOT_CATCH_MSG, 1);
+ if (ret_val == -1)
+ return NULL;
+ }
}
res = PyErr_GivenExceptionMatches(v, w);
break;
More information about the Python-checkins
mailing list