Skip to content

Commit b9ce7cd

Browse files
committed
save_global(): Trying to resolve module.name can fail for two
reasons: importing module can fail, or the attribute lookup module.name can fail. We were giving the same error msg for both cases, making it needlessly hard to guess what went wrong. These cases give different error msgs now.
1 parent 97e5ff5 commit b9ce7cd

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Modules/cPickle.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,14 +2021,16 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
20212021
mod = PyImport_ImportModule(module_str);
20222022
if (mod == NULL) {
20232023
cPickle_ErrFormat(PicklingError,
2024-
"Can't pickle %s: it's not found as %s.%s",
2025-
"OSS", args, module, global_name);
2024+
"Can't pickle %s: import of module %s "
2025+
"failed",
2026+
"OS", args, module);
20262027
goto finally;
20272028
}
20282029
klass = PyObject_GetAttrString(mod, name_str);
20292030
if (klass == NULL) {
20302031
cPickle_ErrFormat(PicklingError,
2031-
"Can't pickle %s: it's not found as %s.%s",
2032+
"Can't pickle %s: attribute lookup %s.%s "
2033+
"failed",
20322034
"OSS", args, module, global_name);
20332035
goto finally;
20342036
}

0 commit comments

Comments
 (0)