pickling protocol 2 is broken, 0 works

3 views
Skip to first unread message

Ondrej Certik

unread,
Nov 12, 2008, 11:57:09 AM11/12/08
to sy...@googlegroups.com
Hi,

I'd like to draw your attention to these two issues:

http://code.google.com/p/sympy/issues/detail?id=1176
http://code.google.com/p/sympy/issues/detail?id=1177

does anyone has any idea where the problem is?

If this works:

In [1]: import pickle

In [2]: pickle.loads(pickle.dumps(sin(4)))
Out[2]: sin(4)

and this fails:

In [3]: pickle.loads(pickle.dumps(sin(4), 2))
ERROR: An unexpected error occurred while tokenizing input

then it almost smells like some problem in python itself. Let's
investigate and if it's a python bug, report to python-dev.

This bug needs to be resolved so that we can use sympy with ipython
parallel stuff that uses protocol 2.

Thanks,
Ondrej

Robert Kern

unread,
Jan 11, 2009, 2:25:50 AM1/11/09
to sy...@googlegroups.com
On Wed, Nov 12, 2008 at 10:57, Ondrej Certik <ond...@certik.cz> wrote:
>
> Hi,
>
> I'd like to draw your attention to these two issues:
>
> http://code.google.com/p/sympy/issues/detail?id=1176
> http://code.google.com/p/sympy/issues/detail?id=1177
>
> does anyone has any idea where the problem is?

Protocol 2 invokes cls.__new__(cls, ()) on new-style classes if you
don't implement __getnewargs__() on your classes. Every time you make
a new class that requires arguments to __new__(), you need to
implement __getnewargs__() to return a tuple that can be passed into
your __new__().

I have a patch on sympy-patches that does this for all of the classes
tested by test_pickle. There may be other classes that don't work.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco

Ondrej Certik

unread,
Jan 11, 2009, 11:20:05 AM1/11/09
to sy...@googlegroups.com
On Sat, Jan 10, 2009 at 11:25 PM, Robert Kern <rober...@gmail.com> wrote:
>
> On Wed, Nov 12, 2008 at 10:57, Ondrej Certik <ond...@certik.cz> wrote:
>>
>> Hi,
>>
>> I'd like to draw your attention to these two issues:
>>
>> http://code.google.com/p/sympy/issues/detail?id=1176
>> http://code.google.com/p/sympy/issues/detail?id=1177
>>
>> does anyone has any idea where the problem is?
>
> Protocol 2 invokes cls.__new__(cls, ()) on new-style classes if you
> don't implement __getnewargs__() on your classes. Every time you make
> a new class that requires arguments to __new__(), you need to
> implement __getnewargs__() to return a tuple that can be passed into
> your __new__().
>
> I have a patch on sympy-patches that does this for all of the classes
> tested by test_pickle. There may be other classes that don't work.

Wow, that's great! Thanks for the work.

I don't see any patches in there:

http://groups.google.com/group/sympy-patches

maybe you forgot to join the group? Unfortunately we need to require
the membership due to spam.

Ondrej

Robert Kern

unread,
Jan 11, 2009, 7:50:55 PM1/11/09
to sy...@googlegroups.com

I've joined, but I think my sendmail configuration may not be working.
git send-email finishes with OK, though. The patch is attached to the
issue.

Ondrej Certik

unread,
Jan 11, 2009, 8:30:14 PM1/11/09
to sy...@googlegroups.com
On Sun, Jan 11, 2009 at 4:50 PM, Robert Kern <rober...@gmail.com> wrote:
>
> On Sun, Jan 11, 2009 at 10:20, Ondrej Certik <ond...@certik.cz> wrote:
>>
>> On Sat, Jan 10, 2009 at 11:25 PM, Robert Kern <rober...@gmail.com> wrote:
>>>
>>> On Wed, Nov 12, 2008 at 10:57, Ondrej Certik <ond...@certik.cz> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'd like to draw your attention to these two issues:
>>>>
>>>> http://code.google.com/p/sympy/issues/detail?id=1176
>>>> http://code.google.com/p/sympy/issues/detail?id=1177
>>>>
>>>> does anyone has any idea where the problem is?
>>>
>>> Protocol 2 invokes cls.__new__(cls, ()) on new-style classes if you
>>> don't implement __getnewargs__() on your classes. Every time you make
>>> a new class that requires arguments to __new__(), you need to
>>> implement __getnewargs__() to return a tuple that can be passed into
>>> your __new__().
>>>
>>> I have a patch on sympy-patches that does this for all of the classes
>>> tested by test_pickle. There may be other classes that don't work.
>>
>> Wow, that's great! Thanks for the work.
>>
>> I don't see any patches in there:
>>
>> http://groups.google.com/group/sympy-patches
>>
>> maybe you forgot to join the group? Unfortunately we need to require
>> the membership due to spam.
>
> I've joined, but I think my sendmail configuration may not be working.
> git send-email finishes with OK, though. The patch is attached to the
> issue.

Ah, I see, thanks. All patches are in, only it exposed one new bug:

http://code.google.com/p/sympy/issues/detail?id=1259

But I almost have a patch for it. I went to ride a bike here in Reno
and it's very cool, nice mountains, so I need to take a shower then
I'll finish the patch.

Ondrej

Reply all
Reply to author
Forward
0 new messages