pycopy-lib icon indicating copy to clipboard operation
pycopy-lib copied to clipboard

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

Open tarakanov opened this issue 6 years ago • 3 comments

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 avatar Sep 23 '19 04:09 tarakanov

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

tarakanov avatar Sep 23 '19 10:09 tarakanov

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 avatar Sep 23 '19 16:09 pfalcon

Also I notice that ujson converts tuple to list silently.

This is likely how original CPython json module works either.

pfalcon avatar Sep 23 '19 16:09 pfalcon