mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #18473: Fixed 2to3 and 3to2 compatible pickle mappings.
Fixed ambigious reverse mappings. Added many new mappings. Import mapping is no longer applied to modules already mapped with full name mapping. Added tests for compatible pickling and unpickling and for consistency of _compat_pickle mappings.
This commit is contained in:
parent
c43a666ba2
commit
bfe1824d08
6 changed files with 326 additions and 30 deletions
|
@ -3026,6 +3026,7 @@ fix_imports(PyObject **module_name, PyObject **global_name)
|
|||
Py_INCREF(fixed_global_name);
|
||||
*module_name = fixed_module_name;
|
||||
*global_name = fixed_global_name;
|
||||
return 0;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
|
@ -6278,20 +6279,21 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self, PyObject *module_name,
|
|||
else if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check if the module was renamed. */
|
||||
item = PyDict_GetItemWithError(st->import_mapping_2to3, module_name);
|
||||
if (item) {
|
||||
if (!PyUnicode_Check(item)) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"_compat_pickle.IMPORT_MAPPING values should be "
|
||||
"strings, not %.200s", Py_TYPE(item)->tp_name);
|
||||
else {
|
||||
/* Check if the module was renamed. */
|
||||
item = PyDict_GetItemWithError(st->import_mapping_2to3, module_name);
|
||||
if (item) {
|
||||
if (!PyUnicode_Check(item)) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"_compat_pickle.IMPORT_MAPPING values should be "
|
||||
"strings, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
module_name = item;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
module_name = item;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue