[pypy-svn] r78065 - in pypy/branch/fast-forward/pypy/module/exceptions: . test

afa at codespeak.net afa at codespeak.net
Mon Oct 18 19:19:57 CEST 2010


Author: afa
Date: Mon Oct 18 19:19:55 2010
New Revision: 78065

Modified:
   pypy/branch/fast-forward/pypy/module/exceptions/interp_exceptions.py
   pypy/branch/fast-forward/pypy/module/exceptions/test/test_exc.py
Log:
This seems enough to fix multiple inheritance of Exception classes:
you don't need a __new__ if the class has the same layout as its base.


Modified: pypy/branch/fast-forward/pypy/module/exceptions/interp_exceptions.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/exceptions/interp_exceptions.py	(original)
+++ pypy/branch/fast-forward/pypy/module/exceptions/interp_exceptions.py	Mon Oct 18 19:19:55 2010
@@ -254,7 +254,6 @@
         base.typedef,
         __doc__ = W_Exc.__doc__,
         __module__ = 'exceptions',
-        __new__ = _new(W_Exc, realbase),
         **kwargs
     )
     W_Exc.typedef.applevel_subclasses_base = realbase

Modified: pypy/branch/fast-forward/pypy/module/exceptions/test/test_exc.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/exceptions/test/test_exc.py	(original)
+++ pypy/branch/fast-forward/pypy/module/exceptions/test/test_exc.py	Mon Oct 18 19:19:55 2010
@@ -68,6 +68,7 @@
         assert isinstance(Exception(), BaseException)
         assert repr(Exception(3, "x")) == "Exception(3, 'x')"
         assert str(IOError("foo", "bar")) == "[Errno foo] bar"
+        assert isinstance(IOError("foo", "bar"), IOError)
 
     def test_custom_class(self):
         from exceptions import Exception, BaseException, LookupError
@@ -185,7 +186,7 @@
         raises(TypeError, UnicodeEncodeError, u"x", u"y", 1, 5, "bah")
 
     def test_multiple_inheritance(self):
-        from exceptions import LookupError, ValueError, Exception
+        from exceptions import LookupError, ValueError, Exception, IOError
         class A(LookupError, ValueError):
             pass
         assert issubclass(A, A)
@@ -209,6 +210,17 @@
         else:
             fail("bah")
 
+        class C(ValueError, IOError):
+            pass
+        c = C()
+        assert isinstance(ValueError(), ValueError)
+        assert isinstance(c, C)
+        assert isinstance(c, Exception)
+        assert isinstance(c, ValueError)
+        assert isinstance(c, IOError)
+        assert isinstance(c, EnvironmentError)
+        assert not isinstance(c, KeyError)
+
     def test_doc_and_module(self):
         import exceptions
         for name, e in exceptions.__dict__.items():



More information about the Pypy-commit mailing list