This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author barry
Recipients barry, benjamin.peterson, doko, martin.panter, serhiy.storchaka
Date 2015-11-30.23:19:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1448925547.29.0.17463965754.issue25698@psf.upfronthosting.co.za>
In-reply-to
Content
I set a breakpoint where the error occurs.  I'm in test_cpickle.py dumps().  Doing cPickle.dumps(arg)  in the bp, I get the error.  arg is:

(Pdb) arg
{<__main__.H object at 0x7ff8e2a870d0>: None}
(Pdb) type(arg)
<class 'test.pickletester.MyDict'>

Look again at the AttributeError:

(Pdb) cPickle.dumps(arg)
*** AttributeError: 'module' object has no attribute '_reduce_ex'

First, why is that trying to find the attribute of a module object instead of the MyDict instance?  I even tried this just to discount the effects of __main__.H:

(Pdb) cPickle.dumps(type(arg)())
*** AttributeError: 'module' object has no attribute '_reduce_ex'

(as you'd expect, type(arg)() is just an instance of a MyDict.

Two questions: why is it trying to get the attribute on a module object, and why is the attribute it's trying to get '_reduce_ex' instead of '__reduce_ex__'?

The attribute to get is taken from the __reduce_ex___str in cPickle.c, which gets defined as:

#define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S)))  return -1;
...
    INIT_STR(__reduce_ex__);

This is a compile-time definition, so it makes no sense that it would be trying to find the wrong attribute in some cases (e.g. when running the full regrtest.py) but not in others (e.g. running just test_cpickle.py).  But I can find no other references to a string containing "reduce_ex" so the cPickle version has to be it.  And that gets initialized in init_stuff(), called from initcPickle() so I don't see any other way for it to get corrupted.

cPickle.dumps({}) works just fine, so it's an artifact of the MyDict.  That's all I've figured out for now.
History
Date User Action Args
2015-11-30 23:19:07barrysetrecipients: + barry, doko, benjamin.peterson, martin.panter, serhiy.storchaka
2015-11-30 23:19:07barrysetmessageid: <1448925547.29.0.17463965754.issue25698@psf.upfronthosting.co.za>
2015-11-30 23:19:07barrylinkissue25698 messages
2015-11-30 23:19:06barrycreate