Almenon / Almenon/AREPL-backend

jsonpickle.decode exhibits different behavior in AREPL than in Pycharm

オープン
#4 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
14
フォーク
8
平均マージ
4日 19時間
マージ済み PR(30日)
4

説明

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。