Skip to content

Commit 2ae6b8e

Browse files
chore: unique list of found globals
1 parent 6a606d1 commit 2ae6b8e

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
@@ -169,14 +169,15 @@ def _find_non_builtin_globals(source, codeobj):
169169
import ast
170170
import builtins
171171

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

181182

182183
def _source_of_function(function):

0 commit comments

Comments
 (0)