-
Notifications
You must be signed in to change notification settings - Fork 6
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
jsonpickle.decode exhibits different behavior in AREPL than in Pycharm #10
Comments
the problem is fixed when you replace execLocals = {} with execLocals = locals(). It must be something missing in locals that causes the error. |
Found it! execLocals was missing the __name__ property. Inserting the following code after execLocals fixes the issue: execLocals['__doc__'] = locals()['__doc__']
execLocals['__file__'] = locals()['__file__']
execLocals['__loader__'] = locals()['__loader__']
execLocals['__name__'] = locals()['__name__']
execLocals['__package__'] = locals()['__package__']
execLocals['__spec__'] = locals()['__spec__'] |
When I tried applying the fix to the pythonEvaluator the fix did not work. I reinvestigated and found out that when you remove the block of code in the beginning: from enum import Enum
from jsonpickle import encode, decode
class C(Enum):
VALUE = 1
my_list_encode = encode(C.VALUE)
decode(my_list_encode) # no error then the fix does not work anymore! I have no idea why the lack of this code would cause an error in execd code - they don't share the same locals. But I have already spent too much time on this - I decided to just remove the v1.0.0-alpha.2 milestone and commit what I had so far. Adding the special vars (__doc__, etc...) is a good idea that should've been done already, even if it didn't fix this particular problem. Also, I found out that the code block above does not work in the console. This means something funky is going on in jsonpickle - possibly if I raise an issue with them the fix would also fix the error in my case. I'll look into this issue again if I have time to investigate it further or someone comments. For now I have more important stuff to do. |
I moved this over to AREPL-backend |
In AREPL json.decode fails to decode a simple pickled enum. In Pycharm the decoding happens without any error. The reason behind this is that AREPL uses exec to execute the user's code. In the example below you can see the exact same code that works outside of exec() fails inside exec().
The text was updated successfully, but these errors were encountered: