-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyobjects behaving weirdly when calling python stdlib package #21796
Comments
I don't know the answer here. The Pyobjects renderer is maintained by @borgstrom, so he may have something to add. I usually recommend using the py renderer if you want python rendering. |
I will at this tonight.
|
WRT your comment:
We don't really hard-parse things that much, the only hand parsing we do is to allow for The cause of this seems to be that we're passing in a globals and locals object that already contain symbols. If I run the code with empty globals & locals it works fine.
I'll keep digging. |
From the Python docs on the `exec` statement: > Remember that at module level, globals and locals are the same dictionary. > If two separate objects are given as globals and locals, the code will be > executed as if it were embedded in a class definition. We were providing a specific object for locals and in the specific case reported in saltstack#21796 this caused a very strange name error when used in a specific way. By removing the explicit locals dictionary and just having the globals dictionary be shared fixes the issue. We didn't use the specific locals dictionary anyways.
From the Python docs on the exec statement: > Remember that at module level, globals and locals are the same dictionary. > If two separate objects are given as globals and locals, the code will be > executed as if it were embedded in a class definition. We were providing a specific object for locals and in the specific case reported in saltstack#21796 this caused a very strange name error when used in a specific way. By removing the explicit locals dictionary and just having the globals dictionary be shared fixes the issue, and we weren't using the specific locals anyway.
This is very interesting. While the fix was to remove the specific locals object I still didn't fully understand what was triggering the behavior, so I've been playing around with this.
The above code has a subtle "problem". The argument to join should be an iterable, but the list comprehension is missing the explicit list or tuple syntax to turn it into an iterable. If I add the syntax to turn the comprehension into a list then the code works under exec:
However, the code succeeds without the list comprehension syntax when invoked directly using the python binary:
I still do not understand what specifically is happening inside the scope of the |
Thanks for fixing this @borgstrom! And also for probing a bit further, this is quite interesting behaviour. |
Refs the discussion in saltstack#21796 (comment)
I am using pyobjects, silly me...
The following code doesn't work:
it fails with this message:
However, it works fine when I separate the line.
Of course, I have
import random, string
at the top of the fileDoes this really hand-parse python up to an arbitrary level of complexity? If yes, please document this, so people don't expect too much.
The text was updated successfully, but these errors were encountered: