Almenon / Almenon/AREPL-backend
jsonpickle.decode exhibits different behavior in AREPL than in Pycharm
- Lingua principale
- Python
- Stelle
- 14
- Fork
- 8
- Merge medio
- 4g 19h
- PR unite (30g)
- 4
Descrizione
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\_\_'
"""
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.