pfalcon / pycopy-lib

Standard library of the Pycopy project, minimalist and light-weight Python language implementation
https://github.com/pfalcon/pycopy
Other
246 stars 70 forks source link

error when pickle dict with float (point sign) and tuple #40

Open tarakanov opened 4 years ago

tarakanov commented 4 years ago

I need to save dict structure to persistent storage using pickle. I have tuples and floats in it. But when I try to unpickle it I got error. To reproduce:

>>> d = {'a': 1.0, 'b': (1, 0)}
>>> pickle.loads(pickle.dumps(d))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pickle.py", line 20, in loads
ImportError: no module named '{'a': 1'
>>> 
tarakanov commented 4 years ago

I solve this replacing tuples with lists. Also I notice that ujson converts tuple to list silently.

pfalcon commented 4 years ago

Thanks for report.

Pickle implementation is very, very basic and was tested with only very simple data structures. Apparently, wasn't tested with floats, as your case suggests. The idea is the same as with the rest of pycopy-lib: someone who would need more functionality might look into implementing it.

To solve it "completely", more planning/thinking/work is needed, e.g. https://github.com/pfalcon/pycopy/issues/8

pfalcon commented 4 years ago

Also I notice that ujson converts tuple to list silently.

This is likely how original CPython json module works either.