Skip to content

Commit ac6f642

Browse files
chore: unique list of found globals
1 parent e5caca1 commit ac6f642

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/execnet/gateway.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,15 @@ def _find_non_builtin_globals(source, codeobj):
172172

173173
import builtins as __builtin__
174174

175-
vars = dict.fromkeys(codeobj.co_varnames)
176-
return [
177-
node.id
178-
for node in ast.walk(ast.parse(source))
179-
if isinstance(node, ast.Name)
180-
and node.id not in vars
181-
and node.id not in __builtin__.__dict__
182-
]
175+
vars = set(codeobj.co_varnames)
176+
vars.update(__builtin__.__dict__)
177+
178+
res = []
179+
for node in ast.walk(ast.parse(source)):
180+
if isinstance(node, ast.Name) and node.id not in vars:
181+
vars.add(node.id)
182+
res.append(node.id)
183+
return res
183184

184185

185186
def _source_of_function(function):

0 commit comments

Comments
 (0)