# HG changeset patch # User paulb@localhost.localdomain # Date 1165445688 -3600 # Node ID 3edadae4cec1d625458ad724a2e0f4b14dcac6fd # Parent 053d9f313f654a4d01a90a5045da4e1a4e42f6f9 Added annotation and viewing support for the global statement. Expanded the test of globals. diff -r 053d9f313f65 -r 3edadae4cec1 annotate.py --- a/annotate.py Wed Dec 06 00:48:29 2006 +0100 +++ b/annotate.py Wed Dec 06 23:54:48 2006 +0100 @@ -117,12 +117,12 @@ types possible when the means of constructing the namespace may depend on run-time behaviour. - Covered: Assign, CheckExc, Conditional, InvokeBlock, InvokeFunction, + Covered: Assign, CheckExc, Conditional, Global, InvokeBlock, InvokeFunction, LoadAttr, LoadExc, LoadName, LoadRef, LoadTemp, Module, Not, Pass, Raise, ReleaseTemp, ReturnFromBlock, ReturnFromFunction, StoreAttr, StoreName, StoreTemp, Subprogram, Try. - Missing: Global, Import. + Missing: Import. """ def __init__(self): @@ -357,6 +357,15 @@ return conditional + def visitGlobal(self, global_): + + """ + Return the 'global_' node unprocessed since namespaces should have + already been altered to take global names into consideration. + """ + + return global_ + def _visitInvoke(self, invoke, invocation_types, have_args): """ diff -r 053d9f313f65 -r 3edadae4cec1 tests/global.py --- a/tests/global.py Wed Dec 06 00:48:29 2006 +0100 +++ b/tests/global.py Wed Dec 06 23:54:48 2006 +0100 @@ -1,10 +1,20 @@ a = 123 + def f(x): global a a = x + def g(a): b = a + +def h(b): + a = b + class A: x = a global a y = a + +f(234) +g(345) +h(456) diff -r 053d9f313f65 -r 3edadae4cec1 viewer.py --- a/viewer.py Wed Dec 06 00:48:29 2006 +0100 +++ b/viewer.py Wed Dec 06 23:54:48 2006 +0100 @@ -126,14 +126,14 @@ Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard, - Div, FloorDiv, For, Function, Getattr, If, Keyword, Lambda, List, - Module, Mul, Name, Not, Or, Pass, Print, Printnl, Raise, Return, - Slice, Stmt, Sub, Subscript, TryExcept, TryFinally, Tuple, + Div, FloorDiv, For, Function, Getattr, Global, If, Keyword, Lambda, + List, Module, Mul, Name, Not, Or, Pass, Print, Printnl, Raise, + Return, Slice, Stmt, Sub, Subscript, TryExcept, TryFinally, Tuple, UnaryAdd, UnarySub, While. Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis, - Exec, From, Global, Import, Invert, LeftShift, ListComp, - ListCompFor, ListCompIf, Mod, Power, RightShift, Sliceobj, Yield. + Exec, From, Import, Invert, LeftShift, ListComp, ListCompFor, + ListCompIf, Mod, Power, RightShift, Sliceobj, Yield. """ def __init__(self, stream): @@ -278,6 +278,17 @@ self.stream.write("\n") self.stream.write("\n") + def visitGlobal(self, node): + self.stream.write("
\n") + self._keyword("global") + first = 1 + for name in node.names: + if not first: + self.stream.write(",\n") + self.stream.write(name) + first = 0 + self.stream.write("
\n") + def visitIf(self, node): self.stream.write("
\n") first = 1