[pypy-svn] r57605 - in pypy/branch/2.5-features: lib-python/modified-2.5.1/test pypy/interpreter pypy/interpreter/test pypy/lib
bgola at codespeak.net
bgola at codespeak.net
Sat Aug 23 16:35:10 CEST 2008
Author: bgola
Date: Sat Aug 23 16:35:09 2008
New Revision: 57605
Added:
pypy/branch/2.5-features/lib-python/modified-2.5.1/test/exception_hierarchy.txt
- copied unchanged from r57542, pypy/branch/2.5-features/lib-python/2.5.1/test/exception_hierarchy.txt
pypy/branch/2.5-features/lib-python/modified-2.5.1/test/test_pep352.py
- copied, changed from r57542, pypy/branch/2.5-features/lib-python/2.5.1/test/test_pep352.py
Modified:
pypy/branch/2.5-features/pypy/interpreter/error.py
pypy/branch/2.5-features/pypy/interpreter/generator.py
pypy/branch/2.5-features/pypy/interpreter/test/test_raise.py
pypy/branch/2.5-features/pypy/lib/_exceptions.py
Log:
bugfixes (PEP352)
Copied: pypy/branch/2.5-features/lib-python/modified-2.5.1/test/test_pep352.py (from r57542, pypy/branch/2.5-features/lib-python/2.5.1/test/test_pep352.py)
==============================================================================
--- pypy/branch/2.5-features/lib-python/2.5.1/test/test_pep352.py (original)
+++ pypy/branch/2.5-features/lib-python/modified-2.5.1/test/test_pep352.py Sat Aug 23 16:35:09 2008
@@ -119,7 +119,8 @@
def tearDown(self):
warnings.filters = self._filters[:]
- def test_raise_classic(self):
+ def XXXtest_raise_classic(self):
+ # PyPy classes are new-style classes by default
class ClassicClass:
pass
try:
Modified: pypy/branch/2.5-features/pypy/interpreter/error.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/error.py (original)
+++ pypy/branch/2.5-features/pypy/interpreter/error.py Sat Aug 23 16:35:09 2008
@@ -150,8 +150,9 @@
if space.full_exceptions:
while space.is_true(space.isinstance(w_type, space.w_tuple)):
w_type = space.getitem(w_type, space.wrap(0))
-
- if space.is_true(space.abstract_isclass(w_type)):
+ if space.full_exceptions and (
+ space.is_true(space.abstract_isclass(w_type)) and
+ space.is_true(space.issubtype(w_type, space.w_BaseException))):
if space.is_w(w_value, space.w_None):
# raise Type: we assume we have to instantiate Type
w_value = space.call_function(w_type)
@@ -177,25 +178,22 @@
space.w_str):
space.warn("raising a string exception is deprecated",
space.w_DeprecationWarning)
- else:
- # raise X: we assume that X is an already-built instance
+ elif space.full_exceptions and space.is_true(space.isinstance(w_type,
+ space.w_BaseException)):
if not space.is_w(w_value, space.w_None):
raise OperationError(space.w_TypeError,
space.wrap("instance exception may not "
"have a separate value"))
w_value = w_type
w_type = space.abstract_getclass(w_value)
+
+ else:
if space.full_exceptions:
- # for the sake of language consistency we should not allow
- # things like 'raise 1', but it is probably fine (i.e.
- # not ambiguous) to allow them in the explicit form
- # 'raise int, 1'
- if (space.findattr(w_value, space.wrap('__dict__')) is None and
- space.findattr(w_value, space.wrap('__slots__')) is None):
- msg = ("raising built-in objects can be ambiguous, "
- "use 'raise type, value' instead")
- raise OperationError(space.w_TypeError, space.wrap(msg))
+ msg = ("exceptions must be classes, or instances,"
+ "or strings (deprecated) not %s" % (w_type.typedef.name))
+ raise OperationError(space.w_TypeError, space.wrap(msg))
+
self.w_type = w_type
self.w_value = w_value
Modified: pypy/branch/2.5-features/pypy/interpreter/generator.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/generator.py (original)
+++ pypy/branch/2.5-features/pypy/interpreter/generator.py Sat Aug 23 16:35:09 2008
@@ -79,27 +79,11 @@
msg = "throw() third argument must be a traceback object"
tb = check_traceback(space, w_tb, msg)
- if space.is_true(space.abstract_isclass(w_type)) and \
- space.is_true(space.issubtype(w_type, space.w_BaseException)):
- exception = OperationError(w_type, w_val, tb)
-
- elif space.is_true(space.isinstance(w_type, space.w_BaseException)):
- if not space.is_w(w_val, space.w_None):
- msg = "instance exception may not have a separate value"
- raise OperationError(space.w_TypeError, space.wrap(msg))
- else:
- exception = OperationError(w_type.getclass(space), w_val, tb)
-
- else:
- if not space.is_true(space.isinstance(w_type, space.w_str)):
- msg = "exceptions must be classes, or instances, not %s" % (
- w_type.typedef.name)
- raise OperationError(space.w_TypeError, space.wrap(msg))
- else:
- exception = OperationError(w_type, w_val, tb)
+ operr = OperationError(w_type, w_val, tb)
+ operr.normalize_exception(space)
ec = space.getexecutioncontext()
- next_instr = self.frame.handle_operation_error(ec, exception)
+ next_instr = self.frame.handle_operation_error(ec, operr)
self.frame.last_instr = intmask(next_instr - 1)
return self.send_ex(space.w_None, True)
Modified: pypy/branch/2.5-features/pypy/interpreter/test/test_raise.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/test/test_raise.py (original)
+++ pypy/branch/2.5-features/pypy/interpreter/test/test_raise.py Sat Aug 23 16:35:09 2008
@@ -1,4 +1,4 @@
-
+import py.test
class AppTestRaise:
def test_arg_as_string(self):
@@ -107,32 +107,25 @@
raises(StopIteration, f)
def test_userclass(self):
+ # PyPy classes are new-style so can't be raised
+
class A:
def __init__(self, x=None):
self.x = x
- class B(A):
- pass
- try:
- raise A
- except A, a:
- assert a.x == None
- try:
- raise A(42)
- except A, a:
- assert a.x == 42
- try:
- raise A, 42
- except A, a:
- assert a.x == 42
- try:
- raise B
- except A, b:
- assert b.__class__ == B
- try:
- raise A, B(42)
- except B, b:
- assert b.__class__ == B
- assert b.x == 42
+
+ def f():
+ try:
+ raise A
+ except A, a:
+ assert a.x == None
+ raises(TypeError, f)
+
+ def f():
+ try:
+ raise A(42)
+ except A, a:
+ assert a.x == 42
+ raises(TypeError, f)
def test_it(self):
C = _classobj('C', (), {})
Modified: pypy/branch/2.5-features/pypy/lib/_exceptions.py
==============================================================================
--- pypy/branch/2.5-features/pypy/lib/_exceptions.py (original)
+++ pypy/branch/2.5-features/pypy/lib/_exceptions.py Sat Aug 23 16:35:09 2008
@@ -81,6 +81,10 @@
def __init__(self, *args):
self.args = args
+ if len(args) == 1:
+ self.message = args[0]
+ else:
+ self.message = ""
def __str__(self):
args = self.args
@@ -125,6 +129,7 @@
"""Unicode translation error."""
def __init__(self, *args):
+ BaseException.__init__(self, *args)
argc = len(args)
self.args = args # modified: always assign args, no error check
if argc == 4:
@@ -186,6 +191,7 @@
"""Base class for I/O related errors."""
def __init__(self, *args):
+ BaseException.__init__(self, *args)
argc = len(args)
self.args = args
self.errno = None
@@ -232,9 +238,6 @@
class NameError(StandardError):
"""Name not found globally."""
-class OverflowWarning(Warning):
- """Base class for warnings about numeric overflow. Won't exist in Python 2.5."""
-
class IOError(EnvironmentError):
"""I/O operation failed."""
@@ -248,6 +251,7 @@
text = None
def __init__(self, *args):
+ BaseException.__init__(self, *args)
argc = len(args)
self.args = args
if argc >= 1:
@@ -296,6 +300,7 @@
"""Request to exit from the interpreter."""
def __init__(self, *args):
+ BaseException.__init__(self, *args)
argc = len(args)
if argc == 0:
self.code = None
More information about the Pypy-commit
mailing list