New submission from Mikhail Korobov:

I think REVERSE_IMPORT_MAPPING is wrong (see 
http://hg.python.org/cpython/file/7272ef213b7c/Lib/_compat_pickle.py#l80 ). It 
relies on dictionary items order and maps 'collections' module to either 
UserString or UserList. This makes it impossible to unpickle collections module 
classes pickled by Python 3.x when using Python 2.x.

>>> import collections
>>> dct = collections.defaultdict()
>>> pickle.dumps(dct, protocol=1)
b'cUserString\ndefaultdict\nq\x00)Rq\x01.'
>>> pickle.dumps(dct, protocol=2, fix_imports=False)
b'ccollections\ndefaultdict\nq\x00)Rq\x01.'

I think pickling of instances of classes from other modules could also suffer. 
I don't think it is a good idea to map io to cStringIO or StringIO, or to map 
http.server to either BaseHTTPServer, SimpleHTTPServer or CGIHTTPServer.

Originally found this issue here: 
https://github.com/nltk/nltk/pull/441/files#L2R67

----------
components: Library (Lib)
messages: 193160
nosy: kmike
priority: normal
severity: normal
status: open
title: some objects pickled by Python 3.x are not unpicklable in Python 2.x 
because of incorrect REVERSE_IMPORT_MAPPING
versions: Python 3.3

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

Reply via email to