andyvand / gmpy

Automatically exported from code.google.com/p/gmpy
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Pickling mpz doesn't work #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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)

Original issue reported on code.google.com by fredrik....@gmail.com on 29 Jul 2008 at 6:40

GoogleCodeExporter commented 9 years ago
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

Original comment by alea...@gmail.com on 4 Aug 2008 at 4:17

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

Original comment by fredrik....@gmail.com on 4 Aug 2008 at 4:26

GoogleCodeExporter commented 9 years ago
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...

Original comment by alea...@gmail.com on 5 Aug 2008 at 2:12

GoogleCodeExporter commented 9 years ago
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.

Original comment by fredrik....@gmail.com on 5 Aug 2008 at 2:20

GoogleCodeExporter commented 9 years ago
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).

Original comment by alea...@gmail.com on 5 Aug 2008 at 2:35

GoogleCodeExporter commented 9 years ago
Pickling works in the current svn trunk thanks to casevh.

Original comment by alea...@gmail.com on 28 Oct 2008 at 2:20