Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbdb28e

Browse files
committed
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 '.'.
1 parent 461922a commit dbdb28e

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

Lib/compiler/symbols.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def get_names(self):
6161
d = {}
6262
d.update(self.defs)
6363
d.update(self.uses)
64+
d.update(self.globals)
6465
return d.keys()
6566

6667
def add_child(self, child):
@@ -111,19 +112,24 @@ def visitFunction(self, node, parent):
111112
self.visit(n, parent)
112113
scope = FunctionScope(node.name, self.module, self.klass)
113114
self.scopes[node] = scope
114-
for name in node.argnames:
115-
scope.add_param(name)
115+
self._do_args(scope, node.argnames)
116116
self.visit(node.code, scope)
117117

118118
def visitLambda(self, node, parent):
119119
for n in node.defaults:
120120
self.visit(n, parent)
121121
scope = LambdaScope(self.module, self.klass)
122122
self.scopes[node] = scope
123-
for name in node.argnames:
124-
scope.add_param(name)
123+
self._do_args(scope, node.argnames)
125124
self.visit(node.code, scope)
126125

126+
def _do_args(self, scope, args):
127+
for name in args:
128+
if type(name) == types.TupleType:
129+
self._do_args(scope, name)
130+
else:
131+
scope.add_param(name)
132+
127133
def visitClass(self, node, parent):
128134
parent.add_def(node.name)
129135
for n in node.bases:
@@ -217,7 +223,7 @@ def list_eq(l1, l2):
217223

218224
def get_names(syms):
219225
return [s for s in [s.get_name() for s in syms.get_symbols()]
220-
if not s.startswith('_[')]
226+
if not (s.startswith('_[') or s.startswith('.'))]
221227

222228
for file in sys.argv[1:]:
223229
print file
@@ -256,6 +262,6 @@ def get_names(syms):
256262
if not list_eq(get_names(s.get_namespace()),
257263
l[0].get_names()):
258264
print s.get_name()
259-
print get_names(s.get_namespace())
260-
print l[0].get_names()
265+
print sort(get_names(s.get_namespace()))
266+
print sort(l[0].get_names())
261267
sys.exit(-1)

Tools/compiler/compiler/symbols.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def get_names(self):
6161
d = {}
6262
d.update(self.defs)
6363
d.update(self.uses)
64+
d.update(self.globals)
6465
return d.keys()
6566

6667
def add_child(self, child):
@@ -111,19 +112,24 @@ def visitFunction(self, node, parent):
111112
self.visit(n, parent)
112113
scope = FunctionScope(node.name, self.module, self.klass)
113114
self.scopes[node] = scope
114-
for name in node.argnames:
115-
scope.add_param(name)
115+
self._do_args(scope, node.argnames)
116116
self.visit(node.code, scope)
117117

118118
def visitLambda(self, node, parent):
119119
for n in node.defaults:
120120
self.visit(n, parent)
121121
scope = LambdaScope(self.module, self.klass)
122122
self.scopes[node] = scope
123-
for name in node.argnames:
124-
scope.add_param(name)
123+
self._do_args(scope, node.argnames)
125124
self.visit(node.code, scope)
126125

126+
def _do_args(self, scope, args):
127+
for name in args:
128+
if type(name) == types.TupleType:
129+
self._do_args(scope, name)
130+
else:
131+
scope.add_param(name)
132+
127133
def visitClass(self, node, parent):
128134
parent.add_def(node.name)
129135
for n in node.bases:
@@ -217,7 +223,7 @@ def list_eq(l1, l2):
217223

218224
def get_names(syms):
219225
return [s for s in [s.get_name() for s in syms.get_symbols()]
220-
if not s.startswith('_[')]
226+
if not (s.startswith('_[') or s.startswith('.'))]
221227

222228
for file in sys.argv[1:]:
223229
print file
@@ -256,6 +262,6 @@ def get_names(syms):
256262
if not list_eq(get_names(s.get_namespace()),
257263
l[0].get_names()):
258264
print s.get_name()
259-
print get_names(s.get_namespace())
260-
print l[0].get_names()
265+
print sort(get_names(s.get_namespace()))
266+
print sort(l[0].get_names())
261267
sys.exit(-1)

0 commit comments

Comments
 (0)