Skip to content

Commit 9dfff19

Browse files
chore: unique list of found globals
1 parent 993be1c commit 9dfff19

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
@@ -187,14 +187,15 @@ def _find_non_builtin_globals(source: str, codeobj: types.CodeType) -> list[str]
187187
import ast
188188
import builtins
189189

190-
vars = dict.fromkeys(codeobj.co_varnames)
191-
return [
192-
node.id
193-
for node in ast.walk(ast.parse(source))
194-
if isinstance(node, ast.Name)
195-
and node.id not in vars
196-
and node.id not in builtins.__dict__
197-
]
190+
vars = set(codeobj.co_varnames)
191+
vars.update(builtins.__dict__)
192+
193+
res = []
194+
for node in ast.walk(ast.parse(source)):
195+
if isinstance(node, ast.Name) and node.id not in vars:
196+
vars.add(node.id)
197+
res.append(node.id)
198+
return res
198199

199200

200201
def _source_of_function(function: types.FunctionType | Callable[..., object]) -> str:

0 commit comments

Comments
 (0)