1.1 --- a/lib/builtins.py Thu Feb 22 22:06:10 2007 +0100
1.2 +++ b/lib/builtins.py Fri Feb 23 00:12:44 2007 +0100
1.3 @@ -765,6 +765,9 @@
1.4 def __init__(self, *args):
1.5 pass
1.6
1.7 +class AssertionError(Exception):
1.8 + __atomic__ = 1
1.9 +
1.10 class AttributeError(Exception):
1.11 __atomic__ = 1
1.12
2.1 --- a/simplified.py Thu Feb 22 22:06:10 2007 +0100
2.2 +++ b/simplified.py Fri Feb 23 00:12:44 2007 +0100
2.3 @@ -109,7 +109,7 @@
2.4 ASTVisitor.__init__(self)
2.5
2.6 def default(self, node, *args):
2.7 - raise ValueError, node.__class__
2.8 + raise SimplifiedError, (None, node)
2.9
2.10 def dispatch(self, node, *args):
2.11 return ASTVisitor.dispatch(self, node, *args)
3.1 --- a/simplify.py Thu Feb 22 22:06:10 2007 +0100
3.2 +++ b/simplify.py Fri Feb 23 00:12:44 2007 +0100
3.3 @@ -47,15 +47,15 @@
3.4 """
3.5 A simplifying visitor for AST nodes.
3.6
3.7 - Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign,
3.8 - Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard,
3.9 - Div, FloorDiv, For, From, Function, Getattr, Global, If, Import,
3.10 - Invert, Keyword, Lambda, List, ListComp, ListCompFor, ListCompIf,
3.11 - Mod, Module, Mul, Name, Not, Or, Pass, Power, Print, Printnl,
3.12 - Raise, Return, Slice, Sliceobj, Stmt, Sub, Subscript, TryExcept,
3.13 - TryFinally, Tuple, While, UnaryAdd, UnarySub.
3.14 + Covered: Add, And, Assert, AssAttr, AssList, AssName, AssTuple, Assign,
3.15 + AugAssign, Break, CallFunc, Class, Compare, Const, Continue, Dict,
3.16 + Discard, Div, FloorDiv, For, From, Function, Getattr, Global, If,
3.17 + Import, Invert, Keyword, Lambda, List, ListComp, ListCompFor,
3.18 + ListCompIf, Mod, Module, Mul, Name, Not, Or, Pass, Power, Print,
3.19 + Printnl, Raise, Return, Slice, Sliceobj, Stmt, Sub, Subscript,
3.20 + TryExcept, TryFinally, Tuple, While, UnaryAdd, UnarySub.
3.21
3.22 - Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis,
3.23 + Missing: Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis,
3.24 Exec, LeftShift, RightShift, Yield.
3.25 """
3.26
3.27 @@ -205,6 +205,32 @@
3.28 result.expr = LoadRef(ref=subprogram)
3.29 return result
3.30
3.31 + def visitAssert(self, assert_):
3.32 + if assert_.fail:
3.33 + fail_args = [self.dispatch(assert_.fail)]
3.34 + else:
3.35 + fail_args = []
3.36 +
3.37 + result = Conditional(assert_, 1,
3.38 + test=self.dispatch(assert_.test),
3.39 + body=[],
3.40 + else_=[
3.41 + Raise(assert_,
3.42 + expr=InvokeFunction(assert_,
3.43 + expr=LoadName(name="AssertionError"),
3.44 + args=fail_args,
3.45 + star=None,
3.46 + dstar=None
3.47 + )
3.48 + )
3.49 + ]
3.50 + )
3.51 +
3.52 + # Make nice annotations for the viewer.
3.53 +
3.54 + assert_._raises = result.else_[0].expr
3.55 + return result
3.56 +
3.57 # Assignments.
3.58
3.59 def visitAssAttr(self, assattr, in_sequence=0):
3.60 @@ -991,7 +1017,7 @@
3.61
3.62 # Make nice annotations for the viewer.
3.63
3.64 - function._subprogram = subprogram
3.65 + lambda_._subprogram = subprogram
3.66
3.67 # Process the lambda contents.
3.68
3.69 @@ -1059,8 +1085,10 @@
3.70 body = self._visitListCompFor(node, quals[1:])
3.71 if qual.ifs:
3.72 body = self._visitListCompIf(node, qual.ifs, body)
3.73 + elif qual.ifs:
3.74 + body = self._visitListCompIf(node, qual.ifs)
3.75 else:
3.76 - body = self._visitListCompIf(node, qual.ifs)
3.77 + body = self._visitListCompBody(node)
3.78 return [self._visitFor(qual, body)]
3.79
3.80 def _visitListCompIf(self, node, ifs, expr=None):
3.81 @@ -1068,17 +1096,7 @@
3.82 if len(ifs) > 1:
3.83 body = self._visitListCompIf(node, ifs[1:], expr)
3.84 elif expr is None:
3.85 - body = [
3.86 - InvokeFunction(
3.87 - expr=LoadAttr(
3.88 - expr=LoadTemp(index="listcomp"),
3.89 - name="append"
3.90 - ),
3.91 - args=[self.dispatch(node.expr)],
3.92 - star=None,
3.93 - dstar=None
3.94 - )
3.95 - ]
3.96 + body = self._visitListCompBody(node)
3.97 else:
3.98 body = expr
3.99 return [
3.100 @@ -1095,6 +1113,19 @@
3.101 )
3.102 ]
3.103
3.104 + def _visitListCompBody(self, node):
3.105 + return [
3.106 + InvokeFunction(
3.107 + expr=LoadAttr(
3.108 + expr=LoadTemp(index="listcomp"),
3.109 + name="append"
3.110 + ),
3.111 + args=[self.dispatch(node.expr)],
3.112 + star=None,
3.113 + dstar=None
3.114 + )
3.115 + ]
3.116 +
3.117 def visitMod(self, mod):
3.118 return self._visitBinary(mod, "__mod__", "__rmod__")
3.119
4.1 --- a/test.py Thu Feb 22 22:06:10 2007 +0100
4.2 +++ b/test.py Fri Feb 23 00:12:44 2007 +0100
4.3 @@ -20,7 +20,7 @@
4.4 try:
4.5 builtins = load(os.path.join("lib", "builtins.py"))
4.6 module = load(sys.argv[1], builtins, None, importer)
4.7 - except AnnotationError, exc:
4.8 + except simplified.SimplifiedError, exc:
4.9 raise
4.10 else:
4.11 if "-d" in sys.argv:
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/assert.py Fri Feb 23 00:12:44 2007 +0100
5.3 @@ -0,0 +1,3 @@
5.4 +x = 123
5.5 +assert x != 456
5.6 +assert x != 123, "Failed!"
6.1 --- a/viewer.py Thu Feb 22 22:06:10 2007 +0100
6.2 +++ b/viewer.py Fri Feb 23 00:12:44 2007 +0100
6.3 @@ -91,7 +91,8 @@
6.4 .operator,
6.5 .iterator,
6.6 .call,
6.7 - .returns
6.8 + .returns,
6.9 + .failure
6.10 {
6.11 position: relative;
6.12 }
6.13 @@ -103,7 +104,8 @@
6.14 .operator:hover > .popup,
6.15 .iterator:hover > .popup,
6.16 .call:hover > .popup,
6.17 - .returns:hover > .popup
6.18 + .returns:hover > .popup,
6.19 + .failure:hover > .popup
6.20 {
6.21 display: block;
6.22 }
6.23 @@ -124,15 +126,15 @@
6.24 """
6.25 A browsing visitor for AST nodes.
6.26
6.27 - Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign,
6.28 - Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard,
6.29 - Div, FloorDiv, For, From, Function, Getattr, Global, If, Import,
6.30 - Keyword, Lambda, List, ListComp, ListCompFor, ListCompIf, Mod,
6.31 - Module, Mul, Name, Not, Or, Pass, Power, Print, Printnl, Raise,
6.32 - Return, Slice, Sliceobj, Stmt, Sub, Subscript, TryExcept,
6.33 + Covered: Add, And, Assert, AssAttr, AssList, AssName, AssTuple, Assign,
6.34 + AugAssign, Break, CallFunc, Class, Compare, Const, Continue, Dict,
6.35 + Discard, Div, FloorDiv, For, From, Function, Getattr, Global, If,
6.36 + Import, Keyword, Lambda, List, ListComp, ListCompFor, ListCompIf,
6.37 + Mod, Module, Mul, Name, Not, Or, Pass, Power, Print, Printnl,
6.38 + Raise, Return, Slice, Sliceobj, Stmt, Sub, Subscript, TryExcept,
6.39 TryFinally, Tuple, UnaryAdd, UnarySub, While.
6.40
6.41 - Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis,
6.42 + Missing: Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis,
6.43 Exec, Invert, LeftShift, RightShift, Yield.
6.44 """
6.45
6.46 @@ -151,6 +153,20 @@
6.47
6.48 # Statements.
6.49
6.50 + def visitAssert(self, node):
6.51 + self.stream.write("<div class='assert'>\n")
6.52 + self.stream.write("<span class='failure'>\n")
6.53 + self._keyword("assert")
6.54 + self._popup(
6.55 + self._types(node._raises.active())
6.56 + )
6.57 + self.stream.write("</span>\n")
6.58 + self.dispatch(node.test)
6.59 + if node.fail:
6.60 + self.stream.write(", ")
6.61 + self.dispatch(node.fail)
6.62 + self.stream.write("</div>\n")
6.63 +
6.64 def visitAssign(self, node):
6.65 self.stream.write("<div class='assign'>\n")
6.66 for lvalue in node.nodes: