Almenon / Almenon/AREPL-backend
jsonpickle.decode exhibits different behavior in AREPL than in Pycharm
- Dominant language
- Python
- Stars
- 14
- Forks
- 8
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 4
Description
porting this issue over from [AREPL](https://github.com/Almenon/AREPL/issues/10)
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().
```python
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
execCode = """ # exact same code as above follows!
from enum import Enum
from jsonpickle import encode, decode
class C(Enum):
VALUE = 1
my_list_encode = encode(C.VALUE)
decode(my_list_encode)
"""
execLocals = {}
exec(execCode,execLocals) # error!
```
> Traceback (most recent call last):
File "C:/dev/random python scripts/misc.py", line 24, in
exec(execCode,execLocals)
File "", line 10, in
File "C:\dev\AREPL\src\python\jsonpickle\__init__.py", line 152, in decode
return unpickler.decode(string, backend=backend, keys=keys)
File "C:\dev\AREPL\src\python\jsonpickle\unpickler.py", line 27, in decode
return context.restore(backend.decode(string), reset=reset)
File "C:\dev\AREPL\src\python\jsonpickle\unpickler.py", line 120, in restore
value = self.\_restore(obj)
File "C:\dev\AREPL\src\python\jsonpickle\unpickler.py", line 162, in \_restore
return restore(obj)
File "C:\dev\AREPL\src\python\jsonpickle\unpickler.py", line 183, in \_restore_reduce
if f == tags.NEWOBJ or f.\_\_name__ == '\_\_newobj\_\_':
AttributeError: 'dict' object has no attribute '\_\_name\_\_'
"""
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.