1.1 --- a/simplify.py Sun Nov 26 15:45:53 2006 +0100
1.2 +++ b/simplify.py Sun Nov 26 21:28:11 2006 +0100
1.3 @@ -352,13 +352,9 @@
1.4 # isinstance(<exc>, <spec>)
1.5
1.6 else:
1.7 - new_spec = self.dispatch(spec)
1.8 test = Conditional(
1.9 - test=InvokeFunction(
1.10 - expr=LoadName(name="isinstance"),
1.11 - args=[LoadExc(), new_spec],
1.12 - star=None,
1.13 - dstar=None)
1.14 + isolate_test=1,
1.15 + test=CheckExc(expr=LoadExc(), choices=self._visitTryExcept(spec))
1.16 )
1.17 test.body = []
1.18
1.19 @@ -390,6 +386,18 @@
1.20 result.handler = results
1.21 return result
1.22
1.23 + def _visitTryExcept(self, spec):
1.24 +
1.25 + "Return a list of nodes for the given exception type 'spec'."
1.26 +
1.27 + if isinstance(spec, compiler.ast.Tuple):
1.28 + nodes = []
1.29 + for node in spec.nodes:
1.30 + nodes += self._visitTryExcept(node)
1.31 + else:
1.32 + nodes = [self.dispatch(spec)]
1.33 + return nodes
1.34 +
1.35 comparison_methods = {
1.36 "==" : "__eq__", "!=" : "__ne__", "<" : "__lt__", "<=" : "__le__",
1.37 ">=" : "__ge__", ">" : "__gt__", "is" : None, "is not" : None