WASasquatch / ASTERR

Abstract Syntax Trees Evaluated Restricted Run (ASTERR) is a Python Script executor for ComfyUI
MIT License
19 stars 5 forks source link

FR: Consider providing a globals namespace to exec #3

Open curiousjp opened 8 months ago

curiousjp commented 8 months ago

Inside functions, we must import our modules as they are scoped from the main script tensor2pil() and pil2tensor() are built-in methods to help with IMAGE input

The current implementation in ASTERR calls exec() with an empty dictionary for the global namespace and the self.params dictionary as the local namespace. As these are different, "the code will be executed as if it were embedded in a class definition", and, as you mention, modules need to be imported inside function definitions. More inconveniently, our functions cannot easily call other functions defined in the code block assembled by ASTERR without having to pass around a bunch of function objects.

I assume this was done to avoid passing the real globals() in, which would allow access to various imports that are not on the whitelist, but is there any risk in providing self.params as both the local and global namespace (including via the shorthand signature for exec)? This allows the code to execute at 'module level', and would allow me to move imports out of function bodies (while still being checked by ast) wile also making my considerably more readable.