From dbdb28e8be50608287b3cfaf8427d7e602f22c2b Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Mon, 9 Apr 2001 20:11:59 +0000 Subject: [PATCH] Add globals to list of names returned by get_names(). Fix func arg processing to handle args in tuples. In test code, skip names beginning with '.'. --- Lib/compiler/symbols.py | 20 +++++++++++++------- Tools/compiler/compiler/symbols.py | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Lib/compiler/symbols.py b/Lib/compiler/symbols.py index 872f174a05d..3ab72f31298 100644 --- a/Lib/compiler/symbols.py +++ b/Lib/compiler/symbols.py @@ -61,6 +61,7 @@ class Scope: d = {} d.update(self.defs) d.update(self.uses) + d.update(self.globals) return d.keys() def add_child(self, child): @@ -111,8 +112,7 @@ class SymbolVisitor: self.visit(n, parent) scope = FunctionScope(node.name, self.module, self.klass) self.scopes[node] = scope - for name in node.argnames: - scope.add_param(name) + self._do_args(scope, node.argnames) self.visit(node.code, scope) def visitLambda(self, node, parent): @@ -120,10 +120,16 @@ class SymbolVisitor: self.visit(n, parent) scope = LambdaScope(self.module, self.klass) self.scopes[node] = scope - for name in node.argnames: - scope.add_param(name) + self._do_args(scope, node.argnames) self.visit(node.code, scope) + def _do_args(self, scope, args): + for name in args: + if type(name) == types.TupleType: + self._do_args(scope, name) + else: + scope.add_param(name) + def visitClass(self, node, parent): parent.add_def(node.name) for n in node.bases: @@ -217,7 +223,7 @@ if __name__ == "__main__": def get_names(syms): return [s for s in [s.get_name() for s in syms.get_symbols()] - if not s.startswith('_[')] + if not (s.startswith('_[') or s.startswith('.'))] for file in sys.argv[1:]: print file @@ -256,6 +262,6 @@ if __name__ == "__main__": if not list_eq(get_names(s.get_namespace()), l[0].get_names()): print s.get_name() - print get_names(s.get_namespace()) - print l[0].get_names() + print sort(get_names(s.get_namespace())) + print sort(l[0].get_names()) sys.exit(-1) diff --git a/Tools/compiler/compiler/symbols.py b/Tools/compiler/compiler/symbols.py index 872f174a05d..3ab72f31298 100644 --- a/Tools/compiler/compiler/symbols.py +++ b/Tools/compiler/compiler/symbols.py @@ -61,6 +61,7 @@ class Scope: d = {} d.update(self.defs) d.update(self.uses) + d.update(self.globals) return d.keys() def add_child(self, child): @@ -111,8 +112,7 @@ class SymbolVisitor: self.visit(n, parent) scope = FunctionScope(node.name, self.module, self.klass) self.scopes[node] = scope - for name in node.argnames: - scope.add_param(name) + self._do_args(scope, node.argnames) self.visit(node.code, scope) def visitLambda(self, node, parent): @@ -120,10 +120,16 @@ class SymbolVisitor: self.visit(n, parent) scope = LambdaScope(self.module, self.klass) self.scopes[node] = scope - for name in node.argnames: - scope.add_param(name) + self._do_args(scope, node.argnames) self.visit(node.code, scope) + def _do_args(self, scope, args): + for name in args: + if type(name) == types.TupleType: + self._do_args(scope, name) + else: + scope.add_param(name) + def visitClass(self, node, parent): parent.add_def(node.name) for n in node.bases: @@ -217,7 +223,7 @@ if __name__ == "__main__": def get_names(syms): return [s for s in [s.get_name() for s in syms.get_symbols()] - if not s.startswith('_[')] + if not (s.startswith('_[') or s.startswith('.'))] for file in sys.argv[1:]: print file @@ -256,6 +262,6 @@ if __name__ == "__main__": if not list_eq(get_names(s.get_namespace()), l[0].get_names()): print s.get_name() - print get_names(s.get_namespace()) - print l[0].get_names() + print sort(get_names(s.get_namespace())) + print sort(l[0].get_names()) sys.exit(-1)