Issue 658693: cPickle does relative import (original) (raw)
save_global() in cPickle calls PyImport_ImportModule() to import the module of a global that's about to be pickled, in order to check whether the given name in fact refers to the given object.
But when it is invoked from code living inside a package, PyImport_ImportModule() first tries a relative import, and if by sheer accident that relative import succeeds, it performs the wrong test.
Example: in a package that has a submodule "exceptions", pickling instances of built-in exceptions will attempt to look up the exception class name in the exceptions submodule rather than in the built-in toplevel module by that name.