Author: Philip Jenvey <pjen...@underboss.org>
Branch: py3k
Changeset: r63843:ac27970cee54
Date: 2013-05-03 18:46 -0700
http://bitbucket.org/pypy/pypy/changeset/ac27970cee54/

Log:    kill BaseException's message/__getitem__

diff --git a/pypy/interpreter/test/test_argument.py 
b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -669,23 +669,23 @@
 class AppTestArgument:
     def test_error_message(self):
         exc = raises(TypeError, (lambda a, b=2: 0), b=3)
-        assert exc.value.message == "<lambda>() takes at least 1 non-keyword 
argument (0 given)"
+        assert str(exc.value) == "<lambda>() takes at least 1 non-keyword 
argument (0 given)"
         exc = raises(TypeError, (lambda: 0), b=3)
-        assert exc.value.message == "<lambda>() takes no arguments (1 given)"
+        assert str(exc.value) == "<lambda>() takes no arguments (1 given)"
         exc = raises(TypeError, (lambda a, b: 0), 1, 2, 3, a=1)
-        assert exc.value.message == "<lambda>() takes exactly 2 arguments (4 
given)"
+        assert str(exc.value) == "<lambda>() takes exactly 2 arguments (4 
given)"
         exc = raises(TypeError, (lambda a, b=1: 0), 1, 2, 3, a=1)
-        assert exc.value.message == "<lambda>() takes at most 2 non-keyword 
arguments (3 given)"
+        assert str(exc.value) == "<lambda>() takes at most 2 non-keyword 
arguments (3 given)"
         exc = raises(TypeError, (lambda a, b=1, **kw: 0), 1, 2, 3)
-        assert exc.value.message == "<lambda>() takes at most 2 non-keyword 
arguments (3 given)"
+        assert str(exc.value) == "<lambda>() takes at most 2 non-keyword 
arguments (3 given)"
         exc = raises(TypeError, (lambda a, b, c=3, **kw: 0), 1)
-        assert exc.value.message == "<lambda>() takes at least 2 arguments (1 
given)"
+        assert str(exc.value) == "<lambda>() takes at least 2 arguments (1 
given)"
         exc = raises(TypeError, (lambda a, b, **kw: 0), 1)
-        assert exc.value.message == "<lambda>() takes exactly 2 non-keyword 
arguments (1 given)"
+        assert str(exc.value) == "<lambda>() takes exactly 2 non-keyword 
arguments (1 given)"
         exc = raises(TypeError, (lambda a, b, c=3, **kw: 0), a=1)
-        assert exc.value.message == "<lambda>() takes at least 2 non-keyword 
arguments (0 given)"
+        assert str(exc.value) == "<lambda>() takes at least 2 non-keyword 
arguments (0 given)"
         exc = raises(TypeError, (lambda a, b, **kw: 0), a=1)
-        assert exc.value.message == "<lambda>() takes exactly 2 non-keyword 
arguments (0 given)"
+        assert str(exc.value) == "<lambda>() takes exactly 2 non-keyword 
arguments (0 given)"
 
     def test_unicode_keywords(self):
         """
diff --git a/pypy/interpreter/test/test_typedef.py 
b/pypy/interpreter/test/test_typedef.py
--- a/pypy/interpreter/test/test_typedef.py
+++ b/pypy/interpreter/test/test_typedef.py
@@ -180,7 +180,7 @@
         self.space.appexec([w_obj], """(obj):
             assert type(obj).__hash__ is None
             err = raises(TypeError, hash, obj)
-            assert err.value.message == "'some_type' objects are unhashable"
+            assert str(err.value) == "'some_type' objects are unhashable"
             """)
 
     def test_destructor(self):
diff --git a/pypy/module/_ffi/test/test_funcptr.py 
b/pypy/module/_ffi/test/test_funcptr.py
--- a/pypy/module/_ffi/test/test_funcptr.py
+++ b/pypy/module/_ffi/test/test_funcptr.py
@@ -574,7 +574,7 @@
         try:
             pow(2, 3)
         except ValueError as e:
-            assert e.message.startswith('Procedure called with')
+            assert str(e).startswith('Procedure called with')
         else:
             assert 0, 'test must assert, wrong calling convention'
 
@@ -595,7 +595,7 @@
         try:
             wrong_sleep(10)
         except ValueError as e:
-            assert e.message.startswith('Procedure called with')
+            assert str(e).startswith('Procedure called with')
         else:
             assert 0, 'test must assert, wrong calling convention'
 
@@ -611,7 +611,7 @@
         try:
             wrong_pow(2, 3) == 8
         except ValueError as e:
-            assert e.message.startswith('Procedure called with')
+            assert str(e).startswith('Procedure called with')
         else:
             assert 0, 'test must assert, wrong calling convention'
 
diff --git a/pypy/module/_rawffi/test/test__rawffi.py 
b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -883,7 +883,7 @@
         try:
             f()
         except ValueError as e:
-            assert "Procedure called with not enough arguments" in e.message
+            assert "Procedure called with not enough arguments" in str(e)
         else:
             assert 0, "Did not raise"
 
@@ -894,7 +894,7 @@
         try:
             f(arg)
         except ValueError as e:
-            assert "Procedure called with too many arguments" in e.message
+            assert "Procedure called with too many arguments" in str(e)
         else:
             assert 0, "Did not raise"
         arg.free()
diff --git a/pypy/module/_socket/test/test_sock_app.py 
b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -708,4 +708,4 @@
         assert isinstance(exc.value, IOError)
         # error is EINVAL, or WSAEINVAL on Windows
         assert exc.value.errno == getattr(errno, 'WSAEINVAL', errno.EINVAL)
-        assert isinstance(exc.value.message, str)
+        assert isinstance(exc.value.strerror, str)
diff --git a/pypy/module/cpyext/test/test_cpyext.py 
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -610,7 +610,7 @@
         if type(exc.value) is not Exception:
             raise exc.value
 
-        assert exc.value.message == "moo!"
+        assert str(exc.value) == "moo!"
 
     def test_refcount(self):
         import sys
@@ -674,7 +674,7 @@
         if type(exc.value) is not Exception:
             raise exc.value
 
-        assert exc.value.message == "moo!"
+        assert str(exc.value) == "moo!"
 
 
     def test_internal_exceptions(self):
diff --git a/pypy/module/exceptions/interp_exceptions.py 
b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -91,11 +91,7 @@
 
 
 class W_BaseException(W_Root):
-    """Superclass representing the base of the exception hierarchy.
-
-    The __getitem__ method is provided for backwards-compatibility
-    and will be deprecated at some point.
-    """
+    """Superclass representing the base of the exception hierarchy."""
     w_dict = None
     args_w = []
     w_cause = None
@@ -103,14 +99,10 @@
     w_traceback = None
 
     def __init__(self, space):
-        self.w_message = space.w_None
+        pass
 
     def descr_init(self, space, args_w):
         self.args_w = args_w
-        if len(args_w) == 1:
-            self.w_message = args_w[0]
-        else:
-            self.w_message = space.wrap("")
 
     def descr_str(self, space):
         lgt = len(self.args_w)
@@ -187,9 +179,6 @@
             w_newtraceback = check_traceback(space, w_newtraceback, msg)
         self.w_traceback = w_newtraceback
 
-    def descr_getitem(self, space, w_index):
-        return space.getitem(space.newtuple(self.args_w), w_index)
-
     def getdict(self, space):
         if self.w_dict is None:
             self.w_dict = space.newdict(instance=True)
@@ -214,32 +203,6 @@
         self.descr_settraceback(space, w_traceback)
         return space.wrap(self)
 
-    def descr_message_get(self, space):
-        w_dict = self.w_dict
-        if w_dict is not None:
-            w_msg = space.finditem(w_dict, space.wrap("message"))
-            if w_msg is not None:
-                return w_msg
-        if self.w_message is None:
-            raise OperationError(space.w_AttributeError,
-                                 space.wrap("message was deleted"))
-        msg = "BaseException.message has been deprecated as of Python 2.6"
-        space.warn(space.wrap(msg), space.w_DeprecationWarning)
-        return self.w_message
-
-    def descr_message_set(self, space, w_new):
-        space.setitem(self.getdict(space), space.wrap("message"), w_new)
-
-    def descr_message_del(self, space):
-        w_dict = self.w_dict
-        if w_dict is not None:
-            try:
-                space.delitem(w_dict, space.wrap("message"))
-            except OperationError, e:
-                if not e.match(space, space.w_KeyError):
-                    raise
-        self.w_message = None
-
 def _new(cls, basecls=None):
     if basecls is None:
         basecls = cls
@@ -261,13 +224,9 @@
     __repr__ = interp2app(W_BaseException.descr_repr),
     __dict__ = GetSetProperty(descr_get_dict, descr_set_dict, descr_del_dict,
                               cls=W_BaseException),
-    __getitem__ = interp2app(W_BaseException.descr_getitem),
     __reduce__ = interp2app(W_BaseException.descr_reduce),
     __setstate__ = interp2app(W_BaseException.descr_setstate),
     with_traceback = interp2app(W_BaseException.descr_with_traceback),
-    message = GetSetProperty(W_BaseException.descr_message_get,
-                            W_BaseException.descr_message_set,
-                            W_BaseException.descr_message_del),
     args = GetSetProperty(W_BaseException.descr_getargs,
                           W_BaseException.descr_setargs),
     __cause__ = GetSetProperty(W_BaseException.descr_getcause,
@@ -547,7 +506,6 @@
         W_BaseException.__init__(self, space)
 
     def descr_init(self, space, args_w):
-        # that's not a self.w_message!!!
         if len(args_w) > 0:
             self.w_msg = args_w[0]
         if len(args_w) == 2:
diff --git a/pypy/module/exceptions/test/test_exc.py 
b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -10,8 +10,8 @@
     def test_baseexc(self):
         assert str(BaseException()) == ''
         assert repr(BaseException()) == 'BaseException()'
-        assert BaseException().message == ''
-        assert BaseException(3).message == 3
+        raises(AttributeError, getattr, BaseException(), 'message')
+        raises(AttributeError, getattr, BaseException(3), 'message')
         assert repr(BaseException(3)) == 'BaseException(3,)'
         assert str(BaseException(3)) == '3'
         assert BaseException().args == ()
@@ -19,16 +19,14 @@
         assert BaseException(3, "x").args == (3, "x")
         assert repr(BaseException(3, "x")) == "BaseException(3, 'x')"
         assert str(BaseException(3, "x")) == "(3, 'x')"
-        assert BaseException(3, "x").message == ''
+        raises(AttributeError, getattr, BaseException(3, "x"), 'message')
         x = BaseException()
         x.xyz = 3
         assert x.xyz == 3
         x.args = [42]
         assert x.args == (42,)
         assert str(x) == '42'
-        assert x[0] == 42
-        x.args = (1, 2, 3)
-        assert x[1:2] == (2,)
+        raises(TypeError, 'x[0] == 42')
         x.message = "xyz"
         assert x.message == "xyz"
         del x.message
@@ -71,7 +69,6 @@
         assert ut.end == 5
         assert ut.reason == 'bah'
         assert ut.args == ('x', 1, 5, 'bah')
-        assert ut.message == ''
         ut.object = 'y'
         assert ut.object == 'y'
         assert str(ut) == "can't translate characters in position 1-4: bah"
@@ -151,7 +148,6 @@
         assert ue.end == 5
         assert ue.reason == 'bah'
         assert ue.args == ('x', 'y', 1, 5, 'bah')
-        assert ue.message == ''
         ue.object = 'z9'
         assert ue.object == 'z9'
         assert str(ue) == "'x' codec can't encode characters in position 1-4: 
bah"
@@ -196,8 +192,8 @@
         assert not isinstance(c, KeyError)
 
     def test_doc_and_module(self):
-        import __exceptions__
-        for name, e in __exceptions__.__dict__.items():
+        import builtins
+        for name, e in builtins.__dict__.items():
             if isinstance(e, type) and issubclass(e, BaseException):
                 assert e.__doc__, e
                 assert e.__module__ == 'builtins', e
@@ -227,7 +223,7 @@
         assert e1.__cause__ is e2
         e1.__cause__ = None
         raises(TypeError, setattr, e1, '__cause__', 1)
-        raises(AttributeError, delattr, e1, '__cause__')
+        raises((AttributeError, TypeError), delattr, e1, '__cause__')
 
     def test_context(self):
         e1 = TypeError()
@@ -237,7 +233,7 @@
         assert e1.__context__ is e2
         e1.__context__ = None
         raises(TypeError, setattr, e1, '__context__', 1)
-        raises(AttributeError, delattr, e1, '__context__')
+        raises((AttributeError, TypeError), delattr, e1, '__context__')
 
     def test_traceback(self):
         assert ValueError().with_traceback(None).__traceback__ is None
diff --git a/pypy/module/marshal/test/test_marshal.py 
b/pypy/module/marshal/test/test_marshal.py
--- a/pypy/module/marshal/test/test_marshal.py
+++ b/pypy/module/marshal/test/test_marshal.py
@@ -178,7 +178,7 @@
     def test_bad_typecode(self):
         import marshal
         exc = raises(ValueError, marshal.loads, b'\x01')
-        assert r"'\x01'" in exc.value.message
+        assert r"'\x01'" in str(exc.value)
 
     def test_bad_data(self):
         import marshal
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
@@ -517,7 +517,7 @@
             dll.get_an_integer()
             assert len(w) == 1
             assert issubclass(w[0].category, RuntimeWarning)
-            assert "C function without declared arguments called" in 
str(w[0].message)
+            assert "C function without declared arguments called" in str(w[0])
 
     def test_errcheck(self):
         py.test.skip('fixme')
@@ -540,7 +540,7 @@
             dll.get_an_integer()
             assert len(w) == 1
             assert issubclass(w[0].category, RuntimeWarning)
-            assert "C function without declared return type called" in 
str(w[0].message)
+            assert "C function without declared return type called" in 
str(w[0])
             
         with warnings.catch_warnings(record=True) as w:
             dll.get_an_integer.restype = None
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py 
b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -41,7 +41,7 @@
 
     con = Connection(":memory:")
     e = pytest.raises(_sqlite3.ProgrammingError, "con.cursor()")
-    assert '__init__' in e.value.message
+    assert '__init__' in str(e.value)
 
 def test_cursor_check_init(con):
     class Cursor(_sqlite3.Cursor):
@@ -50,7 +50,7 @@
 
     cur = Cursor(con)
     e = pytest.raises(_sqlite3.ProgrammingError, "cur.execute('select 1')")
-    assert '__init__' in e.value.message
+    assert '__init__' in str(e.value)
 
 def test_connection_after_close(con):
     pytest.raises(TypeError, "con()")
diff --git a/pypy/module/unicodedata/test/test_unicodedata.py 
b/pypy/module/unicodedata/test/test_unicodedata.py
--- a/pypy/module/unicodedata/test/test_unicodedata.py
+++ b/pypy/module/unicodedata/test/test_unicodedata.py
@@ -71,7 +71,7 @@
                 try:
                     unicodedata.name(char)
                 except ValueError as e:
-                    assert e.message == 'no such name'
+                    assert str(e) == 'no such name'
                 raises(KeyError, unicodedata.lookup, charname)
 
     def test_bug_1704793(self): # from CPython
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to