summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-04-09 20:11:59 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-04-09 20:11:59 (GMT)
commitdbdb28e8be50608287b3cfaf8427d7e602f22c2b (patch)
tree9b02ebb01e98f8c06bc5603081a7fe11697b0275 /Tools
parent461922a005eb6fc4092cd56c129605d3b762f924 (diff)
downloadcpython-dbdb28e8be50608287b3cfaf8427d7e602f22c2b.zip
cpython-dbdb28e8be50608287b3cfaf8427d7e602f22c2b.tar.gz
cpython-dbdb28e8be50608287b3cfaf8427d7e602f22c2b.tar.bz2
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 '.'.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/compiler/compiler/symbols.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/Tools/compiler/compiler/symbols.py b/Tools/compiler/compiler/symbols.py
index 872f174..3ab72f3 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)