Commits

Philip Jenvey committed ac27970

kill BaseException's message/__getitem__

  • Participants
  • Parent commits 5ffc21d
  • Branches py3k

Comments (0)

Files changed (12)

File pypy/interpreter/test/test_argument.py

 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):
         """

File pypy/interpreter/test/test_typedef.py

         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):

File pypy/module/_ffi/test/test_funcptr.py

         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'
 
         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'
 
         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'
 

File pypy/module/_rawffi/test/test__rawffi.py

         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"
 
         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()

File pypy/module/_socket/test/test_sock_app.py

         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)

File pypy/module/cpyext/test/test_cpyext.py

         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
         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):

File pypy/module/exceptions/interp_exceptions.py

 
 
 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
     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)
             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)
         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
     __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,
         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:

File pypy/module/exceptions/test/test_exc.py

     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 == ()
         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
         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"
         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"
         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
         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()
         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

File pypy/module/marshal/test/test_marshal.py

     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

File pypy/module/test_lib_pypy/ctypes_tests/test_functions.py

             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')
             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

File pypy/module/test_lib_pypy/test_sqlite3.py

 
     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):
 
     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()")

File pypy/module/unicodedata/test/test_unicodedata.py

                 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