|
6 | 6 | import sys
|
7 | 7 | from io import StringIO
|
8 | 8 |
|
9 |
| -from compiler import ast, parse, walk, syntax |
| 9 | +import ast |
| 10 | +from compiler import parse, walk, syntax |
10 | 11 | from compiler import pyassem, misc, future, symbols
|
11 | 12 | from compiler.consts import SC_LOCAL, SC_GLOBAL_IMPLICIT, SC_GLOBAL_EXPLICIT, \
|
12 | 13 | SC_FREE, SC_CELL
|
@@ -155,26 +156,30 @@ def visitGlobal(self, node):
|
155 | 156 | for name in node.names:
|
156 | 157 | self.globals.add(name)
|
157 | 158 |
|
158 |
| - def visitFunction(self, node): |
| 159 | + def visitFunctionDef(self, node): |
159 | 160 | self.names.add(node.name)
|
160 | 161 |
|
161 | 162 | def visitLambda(self, node):
|
162 | 163 | pass
|
163 | 164 |
|
164 | 165 | def visitImport(self, node):
|
165 |
| - for name, alias in node.names: |
166 |
| - self.names.add(alias or name) |
| 166 | + for alias in node.names: |
| 167 | + self.names.add(alias.asname or alias.name) |
167 | 168 |
|
168 |
| - def visitFrom(self, node): |
169 |
| - for name, alias in node.names: |
170 |
| - self.names.add(alias or name) |
| 169 | + def visitImportFrom(self, node): |
| 170 | + for alias in node.names: |
| 171 | + self.names.add(alias.asname or alias.name) |
171 | 172 |
|
172 |
| - def visitClass(self, node): |
| 173 | + def visitClassDef(self, node): |
173 | 174 | self.names.add(node.name)
|
174 | 175 |
|
175 | 176 | def visitAssName(self, node):
|
176 | 177 | self.names.add(node.name)
|
177 | 178 |
|
| 179 | + def visitName(self, node): |
| 180 | + if isinstance(node.ctx, ast.Store): |
| 181 | + self.names.add(node.id) |
| 182 | + |
178 | 183 | def is_constant_false(node):
|
179 | 184 | if isinstance(node, ast.Const):
|
180 | 185 | if not node.value:
|
|
0 commit comments