evhub / evhub/coconut

Pickle fails in REPL

Open
#146 2 comments 0 reactions 0 assignees View on GitHub
modification
Dominant language
Python
Stars
4.4k
Forks
142
PR merge metrics
No merged PRs in 30d

Description

This is a bit of a nitpick, but in the interest of total python compatibility:

When the following code is run in the coconut interpreter it fails:

```
import pickle

class C(object): pass

myC = C()

print(pickle.dumps(myC))
```

with

```
>>> print(pickle.dumps(myC))
Traceback (most recent call last):
File "c:\users\oscil\documents\coconut\coconut\coconut\command\utils.py", line 106, in run
return run_func(code, self.vars)
File "c:\users\oscil\documents\coconut\coconut\coconut\command\utils.py", line 68, in try_eval
return eval(code, in_vars)
File "", line 1, in
_pickle.PicklingError: Can't pickle : attribute lookup C on __main__ failed
```

In the python interpreter, it yields the following, as is should:

```
>>> print(pickle.dumps(myC))
b'\x80\x03c__main__\nC\nq\x00)\x81q\x01.'
```

However when compiled with coconut it works.

I think this has something to do with the main module not being registered correctly for pickle to work.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.