cPickle vs pickle discrepancy

Zac Burns zac256 at gmail.com
Thu Jan 8 20:49:22 CET 2009


Correct, 2.6.1 does not complain.

If only I could upgrade! The workaround is obvious and I'll do that.
Thanks for your help.

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games



On Thu, Jan 8, 2009 at 11:34 AM, Carl Banks <pavlovevidence at gmail.com> wrote:
> On Jan 8, 12:27 pm, "Zac Burns" <zac... at gmail.com> wrote:
>> Thanks for your patience waiting for me to isolate the problem.
>>
>> | Package
>> --__init__.py ->empty
>> --Package.py ->empty
>> --Module.py
>>      import cPickle
>>      class C(object):
>>         pass
>>      def fail():
>>         return cPickle.dumps(C(), -1)
>>
>> import Package.Module
>> Package.Module.fail()
>>
>> The failure seems to happen because pickle correctly does an absolute
>> import and cPickle incorrectly relatively imports Package.py and fails
>> to find Module underneath.
>>
>> The package and the module named package was because in there was a
>> main class defined with the same name as the package in that file and
>> Module.py contained support code for the package.
>
> I'd call it a bug.  Nice detecitve work pinpointing it.
>
> I suspect the issue disappears (accidentally) in 2.6, though.  From
> the What's New in Python 2.6 doc:
>
> C API: the PyImport_Import and PyImport_ImportModule functions now
> default to absolute imports, not relative imports. This will affect C
> extensions that import other modules.
>
> Presumably __import__ also defaults to absolute (since PyImport_Import
> calls it) so the two modules should both use absolute imports in 2.6.
>
>
> Carl Banks
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list