[pypy-svn] r15093 - in pypy/dist/pypy/objspace/flow: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Jul 26 11:43:25 CEST 2005
Author: arigo
Date: Tue Jul 26 11:43:25 2005
New Revision: 15093
Modified:
pypy/dist/pypy/objspace/flow/objspace.py
pypy/dist/pypy/objspace/flow/test/test_objspace.py
Log:
Raise implicit exceptions for built-in functions that are
not in the __builtin__ module. This is needed e.g. to
call os.stat() and catch the OSError.
(cfbolz, arigo)
Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/objspace.py Tue Jul 26 11:43:25 2005
@@ -390,10 +390,10 @@
if isinstance(w_callable, Constant):
c = w_callable.value
if not self.builtins_can_raise_exceptions:
- if isinstance(c, (types.BuiltinFunctionType,
- types.BuiltinMethodType)):
- exceptions = None
- elif (isinstance(c, (type, types.ClassType)) and
+ if (isinstance(c, (types.BuiltinFunctionType,
+ types.BuiltinMethodType,
+ types.ClassType,
+ types.TypeType)) and
c.__module__ in ['__builtin__', 'exceptions']):
exceptions = None
self.handle_implicit_exceptions(exceptions)
Modified: pypy/dist/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/test/test_objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/test/test_objspace.py Tue Jul 26 11:43:25 2005
@@ -6,6 +6,7 @@
objspacename = 'flow'
+import os
import operator
is_operator = getattr(operator, 'is_', operator.eq) # it's not there 2.2
@@ -231,6 +232,37 @@
traverse(cannot_reach_exceptblock, x)
#__________________________________________________________
+ def implicitException_int_and_id(x):
+ try:
+ return int(x) + id(x)
+ except ValueError: # not captured by the flow graph!
+ return 0
+
+ def test_implicitException_int_and_id(self):
+ x = self.codetest(self.implicitException_int_and_id)
+ simplify_graph(x)
+ self.show(x)
+ assert len(x.startblock.exits) == 1
+ assert x.startblock.exits[0].target is x.returnblock
+
+ #__________________________________________________________
+ def implicitException_os_stat(x):
+ try:
+ return os.stat(x)
+ except OSError: # *captured* by the flow graph!
+ return 0
+
+ def test_implicitException_os_stat(self):
+ x = self.codetest(self.implicitException_os_stat)
+ simplify_graph(x)
+ self.show(x)
+ assert len(x.startblock.exits) == 3
+ d = {}
+ for link in x.startblock.exits:
+ d[link.exitcase] = True
+ assert d == {None: True, OSError: True, Exception: True}
+
+ #__________________________________________________________
def reraiseKeyError(dic):
try:
x = dic[5]
More information about the Pypy-commit
mailing list