@@ -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
255258def get_names_in_store_context (tree , * , stop , collect , ** kw ):
0 commit comments