Issue 19834: Unpickling exceptions pickled by Python 2 (original) (raw)
Exception objects that have been pickled with Python 2 can not be unpickled with Python 3, even when fix_imports=True is specified:
$ python2.7 Python 2.7.2 (default, Aug 30 2011, 11:04:13) [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import pickle pickle.dumps(StopIteration()) 'cexceptions\nStopIteration\np0\n(tRp1\n.'
$ python3.3 Python 3.3.2 (default, Nov 14 2013, 12:22:14) [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux Type "help", "copyright", "credits" or "license" for more information.
import pickle pickle.loads(b'cexceptions\nStopIteration\np0\n(tRp1\n.', fix_imports=True) Traceback (most recent call last): File "", line 1, in ImportError: No module named 'exceptions'
Adding an entry "exceptions": "builtins" to _compat_pickle.IMPORT_MAPPING seems to fix the problem.
OK, here is a patch. Instead of mapping the exceptions module to builtins, it does the mapping for each exception class separately. I've excluded StandardError, because I think there's no appropriate equivalent in Python 3.