Export to GitHub

gmpy - issue #9

Pickling mpz doesn't work


Posted on Jul 29, 2008 by Helpful Kangaroo

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import gmpy >>> gmpy.version() '1.03' >>> import pickle >>> pickle.dumps(gmpy.mpz(3)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python25\lib\pickle.py", line 1366, in dumps Pickler(file, protocol).dump(obj) File "C:\Python25\lib\pickle.py", line 224, in dump self.save(obj) File "C:\Python25\lib\pickle.py", line 313, in save (t.name, obj)) pickle.PicklingError: Can't pickle 'mpz' object: mpz(3)

Comment #1

Posted on Aug 4, 2008 by Quick Dog

gmpy has never claimed it supports pickling, so this is not a defect, but an "enhancement request" -- you want extra features here, NOT a bug fix!

Thanks,

Alex

Comment #2

Posted on Aug 4, 2008 by Helpful Kangaroo

I agree, but I couldn't help that. All issues submitted by non-developers automatically get labeled with "Defect".

Comment #3

Posted on Aug 5, 2008 by Quick Dog

Heh, you're right, sorry. So anyway, I suggest a trivial Python workaround if you need to pickle gmpy.mpz's...:

import gmpy, copy_reg def reducer(an_mpz): return (gmpy.mpz, (anmpz.binary(), 256)) copy_reg.pickle(type(gmpy.mpz(0)), reducer)

I'm inclined to close this issue but I'd like to check that you agree with me that this fix is satisfactory...

Comment #4

Posted on Aug 5, 2008 by Helpful Kangaroo

I already have a similar workaround. If there is a simple way to support pickling without the need for any workarounds, it would be a nice feature, though. If not, no problem.

Comment #5

Posted on Aug 5, 2008 by Quick Dog

I could add that Python code to the other Python code that's hiding in gmpy (and gets executed when you import it) but while "simple" that's pretty dirty (and would slow down the import a bit for everybody who's not doing pickling -- presumably EVERY user of gmpy, since gmpy never supported pickling). I'm also quite doubtful whether this tiny "extra functionality" deserves a new release (with all the hassles of building Windows and Mac binaries).

Comment #6

Posted on Oct 28, 2008 by Quick Dog

Pickling works in the current svn trunk thanks to casevh.

Status: Fixed

Labels:
Type-Enhancement Priority-Medium