Barry A. Warsaw added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25698>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to