Almenon / Almenon/AREPL-backend

jsonpickle.decode exhibits different behavior in AREPL than in Pycharm

Offen
#4 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
Python
Sterne
14
Forks
8
Ø Merge
4 T. 19 Std.
Gemergte PRs (30 T.)
4

Beschreibung

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\_\_'
"""

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.