Skip to content

Commit 0a34cb4

Browse files
committed
scopeanalyzer: small fixes
1 parent bf95c13 commit 0a34cb4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

unpythonic/syntax/scopeanalyzer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ def get_lexical_variables(tree, collect_locals=True):
170170
(created by assignment), formal parameters of function definitions,
171171
or names declared ``nonlocal`` or ``global``.
172172
"""
173+
if not isnewscope(tree):
174+
raise TypeError("Expected a tree representing a lexical scope, got {}".format(type(tree)))
175+
173176
if type(tree) in (Lambda, FunctionDef, AsyncFunctionDef):
174177
a = tree.args
175178
argnames = [x.arg for x in a.args + a.kwonlyargs]
@@ -185,7 +188,7 @@ def get_lexical_variables(tree, collect_locals=True):
185188
fname = [tree.name]
186189

187190
if collect_locals:
188-
localvars = uniqify(get_names_in_store_context.collect(tree.body))
191+
localvars = list(uniqify(get_names_in_store_context.collect(tree.body)))
189192

190193
@Walker
191194
def getnonlocals(tree, *, stop, collect, **kw):
@@ -244,12 +247,12 @@ def extractnames(tree, *, collect, **kw):
244247
collect(tree.id)
245248
return tree
246249
targetnames.extend(extractnames.collect(g.target))
247-
else:
250+
else: # pragma: no cover
248251
assert False, "Scope analyzer: unimplemented: comprehension target of type {}".type(g.target)
249252

250253
return list(uniqify(targetnames)), []
251254

252-
return [], []
255+
assert False # cannot happen # pragma: no cover
253256

254257
@Walker
255258
def get_names_in_store_context(tree, *, stop, collect, **kw):

0 commit comments

Comments
 (0)