[Python-3000-checkins] r55406 - in python/branches/p3yk: Include/pyerrors.h Lib/test/test_exceptions.py Lib/test/test_pep352.py Misc/NEWS Objects/exceptions.c

brett.cannon python-3000-checkins at python.org
Thu May 17 20:05:38 CEST 2007


Author: brett.cannon
Date: Thu May 17 20:05:37 2007
New Revision: 55406

Modified:
   python/branches/p3yk/Include/pyerrors.h
   python/branches/p3yk/Lib/test/test_exceptions.py
   python/branches/p3yk/Lib/test/test_pep352.py
   python/branches/p3yk/Misc/NEWS
   python/branches/p3yk/Objects/exceptions.c
Log:
Remove BaseException.message (deprecated in Python 2.6).


Modified: python/branches/p3yk/Include/pyerrors.h
==============================================================================
--- python/branches/p3yk/Include/pyerrors.h	(original)
+++ python/branches/p3yk/Include/pyerrors.h	Thu May 17 20:05:37 2007
@@ -10,14 +10,12 @@
     PyObject_HEAD
     PyObject *dict;
     PyObject *args;
-    PyObject *message;
 } PyBaseExceptionObject;
 
 typedef struct {
     PyObject_HEAD
     PyObject *dict;
     PyObject *args;
-    PyObject *message;
     PyObject *msg;
     PyObject *filename;
     PyObject *lineno;
@@ -31,7 +29,6 @@
     PyObject_HEAD
     PyObject *dict;
     PyObject *args;
-    PyObject *message;
     PyObject *encoding;
     PyObject *object;
     PyObject *start;
@@ -44,7 +41,6 @@
     PyObject_HEAD
     PyObject *dict;
     PyObject *args;
-    PyObject *message;
     PyObject *code;
 } PySystemExitObject;
 
@@ -52,7 +48,6 @@
     PyObject_HEAD
     PyObject *dict;
     PyObject *args;
-    PyObject *message;
     PyObject *myerrno;
     PyObject *strerror;
     PyObject *filename;
@@ -63,7 +58,6 @@
     PyObject_HEAD
     PyObject *dict;
     PyObject *args;
-    PyObject *message;
     PyObject *myerrno;
     PyObject *strerror;
     PyObject *filename;

Modified: python/branches/p3yk/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_exceptions.py	(original)
+++ python/branches/p3yk/Lib/test/test_exceptions.py	Thu May 17 20:05:37 2007
@@ -11,7 +11,6 @@
 
 from test.test_support import (TESTFN, unlink, run_unittest,
                                 guard_warnings_filter)
-from test.test_pep352 import ignore_message_warning
 
 # XXX This is not really enough, each *operation* should be tested!
 
@@ -205,109 +204,107 @@
         # test that exception attributes are happy
 
         exceptionList = [
-            (BaseException, (), {'message' : '', 'args' : ()}),
-            (BaseException, (1, ), {'message' : 1, 'args' : (1,)}),
+            (BaseException, (), {'args' : ()}),
+            (BaseException, (1, ), {'args' : (1,)}),
             (BaseException, ('foo',),
-                {'message' : 'foo', 'args' : ('foo',)}),
+                {'args' : ('foo',)}),
             (BaseException, ('foo', 1),
-                {'message' : '', 'args' : ('foo', 1)}),
+                {'args' : ('foo', 1)}),
             (SystemExit, ('foo',),
-                {'message' : 'foo', 'args' : ('foo',), 'code' : 'foo'}),
+                {'args' : ('foo',), 'code' : 'foo'}),
             (IOError, ('foo',),
-                {'message' : 'foo', 'args' : ('foo',), 'filename' : None,
+                {'args' : ('foo',), 'filename' : None,
                  'errno' : None, 'strerror' : None}),
             (IOError, ('foo', 'bar'),
-                {'message' : '', 'args' : ('foo', 'bar'), 'filename' : None,
+                {'args' : ('foo', 'bar'), 'filename' : None,
                  'errno' : 'foo', 'strerror' : 'bar'}),
             (IOError, ('foo', 'bar', 'baz'),
-                {'message' : '', 'args' : ('foo', 'bar'), 'filename' : 'baz',
+                {'args' : ('foo', 'bar'), 'filename' : 'baz',
                  'errno' : 'foo', 'strerror' : 'bar'}),
             (IOError, ('foo', 'bar', 'baz', 'quux'),
-                {'message' : '', 'args' : ('foo', 'bar', 'baz', 'quux')}),
+                {'args' : ('foo', 'bar', 'baz', 'quux')}),
             (EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'),
-                {'message' : '', 'args' : ('errnoStr', 'strErrorStr'),
+                {'args' : ('errnoStr', 'strErrorStr'),
                  'strerror' : 'strErrorStr', 'errno' : 'errnoStr',
                  'filename' : 'filenameStr'}),
             (EnvironmentError, (1, 'strErrorStr', 'filenameStr'),
-                {'message' : '', 'args' : (1, 'strErrorStr'), 'errno' : 1,
+                {'args' : (1, 'strErrorStr'), 'errno' : 1,
                  'strerror' : 'strErrorStr', 'filename' : 'filenameStr'}),
-            (SyntaxError, (), {'message' : '', 'msg' : None, 'text' : None,
+            (SyntaxError, (), {'msg' : None, 'text' : None,
                 'filename' : None, 'lineno' : None, 'offset' : None,
                 'print_file_and_line' : None}),
             (SyntaxError, ('msgStr',),
-                {'message' : 'msgStr', 'args' : ('msgStr',), 'text' : None,
+                {'args' : ('msgStr',), 'text' : None,
                  'print_file_and_line' : None, 'msg' : 'msgStr',
                  'filename' : None, 'lineno' : None, 'offset' : None}),
             (SyntaxError, ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr',
                            'textStr')),
-                {'message' : '', 'offset' : 'offsetStr', 'text' : 'textStr',
+                {'offset' : 'offsetStr', 'text' : 'textStr',
                  'args' : ('msgStr', ('filenameStr', 'linenoStr',
                                       'offsetStr', 'textStr')),
                  'print_file_and_line' : None, 'msg' : 'msgStr',
                  'filename' : 'filenameStr', 'lineno' : 'linenoStr'}),
             (SyntaxError, ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr',
                            'textStr', 'print_file_and_lineStr'),
-                {'message' : '', 'text' : None,
+                {'text' : None,
                  'args' : ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr',
                            'textStr', 'print_file_and_lineStr'),
                  'print_file_and_line' : None, 'msg' : 'msgStr',
                  'filename' : None, 'lineno' : None, 'offset' : None}),
-            (UnicodeError, (), {'message' : '', 'args' : (),}),
+            (UnicodeError, (), {'args' : (),}),
             (UnicodeEncodeError, ('ascii', u'a', 0, 1, 'ordinal not in range'),
-                {'message' : '', 'args' : ('ascii', u'a', 0, 1,
+                {'args' : ('ascii', u'a', 0, 1,
                                            'ordinal not in range'),
                  'encoding' : 'ascii', 'object' : u'a',
                  'start' : 0, 'reason' : 'ordinal not in range'}),
             (UnicodeDecodeError, ('ascii', '\xff', 0, 1, 'ordinal not in range'),
-                {'message' : '', 'args' : ('ascii', '\xff', 0, 1,
+                {'args' : ('ascii', '\xff', 0, 1,
                                            'ordinal not in range'),
                  'encoding' : 'ascii', 'object' : '\xff',
                  'start' : 0, 'reason' : 'ordinal not in range'}),
             (UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"),
-                {'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
+                {'args' : (u'\u3042', 0, 1, 'ouch'),
                  'object' : u'\u3042', 'reason' : 'ouch',
                  'start' : 0, 'end' : 1}),
         ]
         try:
             exceptionList.append(
                 (WindowsError, (1, 'strErrorStr', 'filenameStr'),
-                    {'message' : '', 'args' : (1, 'strErrorStr'),
+                    {'args' : (1, 'strErrorStr'),
                      'strerror' : 'strErrorStr', 'winerror' : 1,
                      'errno' : 22, 'filename' : 'filenameStr'})
             )
         except NameError:
             pass
 
-        with guard_warnings_filter():
-            ignore_message_warning()
-            for exc, args, expected in exceptionList:
-                try:
-                    raise exc(*args)
-                except BaseException as e:
-                    if type(e) is not exc:
-                        raise
-                    # Verify module name
-                    self.assertEquals(type(e).__module__, '__builtin__')
-                    # Verify no ref leaks in Exc_str()
-                    s = str(e)
-                    for checkArgName in expected:
-                        self.assertEquals(repr(getattr(e, checkArgName)),
-                                          repr(expected[checkArgName]),
-                                          'exception "%s", attribute "%s"' %
-                                           (repr(e), checkArgName))
-
-                    # test for pickling support
-                    for p in pickle, cPickle:
-                        if p is None:
-                            continue # cPickle not found -- skip it
-                        for protocol in range(p.HIGHEST_PROTOCOL + 1):
-                            new = p.loads(p.dumps(e, protocol))
-                            for checkArgName in expected:
-                                got = repr(getattr(new, checkArgName))
-                                want = repr(expected[checkArgName])
-                                self.assertEquals(got, want,
-                                                  'pickled "%r", attribute "%s' %
-                                                  (e, checkArgName))
+        for exc, args, expected in exceptionList:
+            try:
+                raise exc(*args)
+            except BaseException as e:
+                if type(e) is not exc:
+                    raise
+                # Verify module name
+                self.assertEquals(type(e).__module__, '__builtin__')
+                # Verify no ref leaks in Exc_str()
+                s = str(e)
+                for checkArgName in expected:
+                    self.assertEquals(repr(getattr(e, checkArgName)),
+                                      repr(expected[checkArgName]),
+                                      'exception "%s", attribute "%s"' %
+                                       (repr(e), checkArgName))
+
+                # test for pickling support
+                for p in pickle, cPickle:
+                    if p is None:
+                        continue # cPickle not found -- skip it
+                    for protocol in range(p.HIGHEST_PROTOCOL + 1):
+                        new = p.loads(p.dumps(e, protocol))
+                        for checkArgName in expected:
+                            got = repr(getattr(new, checkArgName))
+                            want = repr(expected[checkArgName])
+                            self.assertEquals(got, want,
+                                              'pickled "%r", attribute "%s' %
+                                              (e, checkArgName))
 
     def testKeywordArgs(self):
         # test that builtin exception don't take keyword args,

Modified: python/branches/p3yk/Lib/test/test_pep352.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_pep352.py	(original)
+++ python/branches/p3yk/Lib/test/test_pep352.py	Thu May 17 20:05:37 2007
@@ -5,12 +5,6 @@
 import os
 from platform import system as platform_system
 
-def ignore_message_warning():
-    """Ignore the DeprecationWarning for BaseException.message."""
-    warnings.resetwarnings()
-    warnings.filterwarnings("ignore", "BaseException.message",
-                            DeprecationWarning)
-
 
 class ExceptionClassTests(unittest.TestCase):
 
@@ -21,12 +15,10 @@
         self.failUnless(issubclass(Exception, object))
 
     def verify_instance_interface(self, ins):
-        with guard_warnings_filter():
-            ignore_message_warning()
-            for attr in ("args", "message", "__str__", "__repr__"):
-                self.failUnless(hasattr(ins, attr),
-                        "%s missing %s attribute" %
-                            (ins.__class__.__name__, attr))
+        for attr in ("args", "__str__", "__repr__"):
+            self.failUnless(hasattr(ins, attr),
+                    "%s missing %s attribute" %
+                        (ins.__class__.__name__, attr))
 
     def test_inheritance(self):
         # Make sure the inheritance hierarchy matches the documentation
@@ -89,7 +81,7 @@
             inheritance_tree.close()
         self.failUnlessEqual(len(exc_set), 0, "%s not accounted for" % exc_set)
 
-    interface_tests = ("length", "args", "message", "str", "unicode", "repr")
+    interface_tests = ("length", "args", "str", "unicode", "repr")
 
     def interface_test_driver(self, results):
         for test_name, (given, expected) in zip(self.interface_tests, results):
@@ -100,59 +92,30 @@
         # Make sure interface works properly when given a single argument
         arg = "spam"
         exc = Exception(arg)
-        with guard_warnings_filter():
-            ignore_message_warning()
-            results = ([len(exc.args), 1], [exc.args[0], arg],
-                       [exc.message, arg],
-                       [str(exc), str(arg)], [unicode(exc), unicode(arg)],
-                [repr(exc), exc.__class__.__name__ + repr(exc.args)])
-            self.interface_test_driver(results)
+        results = ([len(exc.args), 1], [exc.args[0], arg],
+                   [str(exc), str(arg)], [unicode(exc), unicode(arg)],
+            [repr(exc), exc.__class__.__name__ + repr(exc.args)])
+        self.interface_test_driver(results)
 
     def test_interface_multi_arg(self):
         # Make sure interface correct when multiple arguments given
         arg_count = 3
         args = tuple(range(arg_count))
         exc = Exception(*args)
-        with guard_warnings_filter():
-            ignore_message_warning()
-            results = ([len(exc.args), arg_count], [exc.args, args],
-                    [exc.message, ''], [str(exc), str(args)],
-                    [unicode(exc), unicode(args)],
-                    [repr(exc), exc.__class__.__name__ + repr(exc.args)])
-            self.interface_test_driver(results)
+        results = ([len(exc.args), arg_count], [exc.args, args],
+                [str(exc), str(args)],
+                [unicode(exc), unicode(args)],
+                [repr(exc), exc.__class__.__name__ + repr(exc.args)])
+        self.interface_test_driver(results)
 
     def test_interface_no_arg(self):
         # Make sure that with no args that interface is correct
         exc = Exception()
-        with guard_warnings_filter():
-            ignore_message_warning()
-            results = ([len(exc.args), 0], [exc.args, tuple()],
-                    [exc.message, ''],
-                    [str(exc), ''], [unicode(exc), u''],
-                    [repr(exc), exc.__class__.__name__ + '()'])
-            self.interface_test_driver(results)
-
-
-    def test_message_deprecation(self):
-        # As of Python 2.6, BaseException.message is deprecated.
-        with guard_warnings_filter():
-            warnings.resetwarnings()
-            warnings.filterwarnings('error')
+        results = ([len(exc.args), 0], [exc.args, tuple()],
+                [str(exc), ''], [unicode(exc), u''],
+                [repr(exc), exc.__class__.__name__ + '()'])
+        self.interface_test_driver(results)
 
-            try:
-                BaseException().message
-            except DeprecationWarning:
-                pass
-            else:
-                self.fail("BaseException.message not deprecated")
-
-            exc = BaseException()
-            try:
-                exc.message = ''
-            except DeprecationWarning:
-                pass
-            else:
-                self.fail("BaseException.message assignment not deprecated")
 
 class UsageTests(unittest.TestCase):
 

Modified: python/branches/p3yk/Misc/NEWS
==============================================================================
--- python/branches/p3yk/Misc/NEWS	(original)
+++ python/branches/p3yk/Misc/NEWS	Thu May 17 20:05:37 2007
@@ -26,6 +26,8 @@
 Core and Builtins
 -----------------
 
+- Remove BaseException.message.
+
 - Remove strop module.
 
 - Remove tuple parameter unpacking (PEP 3113).

Modified: python/branches/p3yk/Objects/exceptions.c
==============================================================================
--- python/branches/p3yk/Objects/exceptions.c	(original)
+++ python/branches/p3yk/Objects/exceptions.c	Thu May 17 20:05:37 2007
@@ -27,7 +27,7 @@
     if (!self)
         return NULL;
     /* the dict is created on the fly in PyObject_GenericSetAttr */
-    self->message = self->dict = NULL;
+    self->dict = NULL;
 
     self->args = PyTuple_New(0);
     if (!self->args) {
@@ -35,12 +35,6 @@
         return NULL;
     }
 
-    self->message = PyString_FromString("");
-    if (!self->message) {
-        Py_DECREF(self);
-        return NULL;
-    }
-
     return (PyObject *)self;
 }
 
@@ -54,11 +48,6 @@
     self->args = args;
     Py_INCREF(self->args);
 
-    if (PyTuple_GET_SIZE(self->args) == 1) {
-        Py_CLEAR(self->message);
-        self->message = PyTuple_GET_ITEM(self->args, 0);
-        Py_INCREF(self->message);
-    }
     return 0;
 }
 
@@ -67,7 +56,6 @@
 {
     Py_CLEAR(self->dict);
     Py_CLEAR(self->args);
-    Py_CLEAR(self->message);
     return 0;
 }
 
@@ -84,7 +72,6 @@
 {
     Py_VISIT(self->dict);
     Py_VISIT(self->args);
-    Py_VISIT(self->message);
     return 0;
 }
 
@@ -231,42 +218,10 @@
     return 0;
 }
 
-static PyObject *
-BaseException_get_message(PyBaseExceptionObject *self)
-{
-	int ret;
-	ret = PyErr_WarnEx(PyExc_DeprecationWarning,
-				"BaseException.message has been deprecated as "
-					"of Python 2.6",
-				1);
-	if (ret == -1)
-		return NULL;
-
-	Py_INCREF(self->message);
-	return self->message;
-}
-
-static int
-BaseException_set_message(PyBaseExceptionObject *self, PyObject *val)
-{
-	int ret;
-	ret = PyErr_WarnEx(PyExc_DeprecationWarning,
-				"BaseException.message has been deprecated as "
-					"of Python 2.6",
-				1);
-	if (ret == -1)
-		return -1;
-	Py_INCREF(val);
-	Py_DECREF(self->message);
-	self->message = val;
-	return 0;
-}
 
 static PyGetSetDef BaseException_getset[] = {
     {"__dict__", (getter)BaseException_get_dict, (setter)BaseException_set_dict},
     {"args", (getter)BaseException_get_args, (setter)BaseException_set_args},
-    {"message", (getter)BaseException_get_message,
-	    (setter)BaseException_set_message},
     {NULL},
 };
 
@@ -453,8 +408,6 @@
 }
 
 static PyMemberDef SystemExit_members[] = {
-    {"message", T_OBJECT, offsetof(PySystemExitObject, message), 0,
-        PyDoc_STR("exception message")},
     {"code", T_OBJECT, offsetof(PySystemExitObject, code), 0,
         PyDoc_STR("exception code")},
     {NULL}  /* Sentinel */
@@ -655,8 +608,6 @@
 }
 
 static PyMemberDef EnvironmentError_members[] = {
-    {"message", T_OBJECT, offsetof(PyEnvironmentErrorObject, message), 0,
-        PyDoc_STR("exception message")},
     {"errno", T_OBJECT, offsetof(PyEnvironmentErrorObject, myerrno), 0,
         PyDoc_STR("exception errno")},
     {"strerror", T_OBJECT, offsetof(PyEnvironmentErrorObject, strerror), 0,
@@ -888,8 +839,6 @@
 }
 
 static PyMemberDef WindowsError_members[] = {
-    {"message", T_OBJECT, offsetof(PyWindowsErrorObject, message), 0,
-        PyDoc_STR("exception message")},
     {"errno", T_OBJECT, offsetof(PyWindowsErrorObject, myerrno), 0,
         PyDoc_STR("POSIX exception code")},
     {"strerror", T_OBJECT, offsetof(PyWindowsErrorObject, strerror), 0,
@@ -1120,8 +1069,6 @@
 }
 
 static PyMemberDef SyntaxError_members[] = {
-    {"message", T_OBJECT, offsetof(PySyntaxErrorObject, message), 0,
-        PyDoc_STR("exception message")},
     {"msg", T_OBJECT, offsetof(PySyntaxErrorObject, msg), 0,
         PyDoc_STR("exception msg")},
     {"filename", T_OBJECT, offsetof(PySyntaxErrorObject, filename), 0,
@@ -1554,8 +1501,6 @@
 }
 
 static PyMemberDef UnicodeError_members[] = {
-    {"message", T_OBJECT, offsetof(PyUnicodeErrorObject, message), 0,
-        PyDoc_STR("exception message")},
     {"encoding", T_OBJECT, offsetof(PyUnicodeErrorObject, encoding), 0,
         PyDoc_STR("exception encoding")},
     {"object", T_OBJECT, offsetof(PyUnicodeErrorObject, object), 0,


More information about the Python-3000-checkins mailing list