[issue29546] A more helpful ImportError message
Matthias Bussonnier
report at bugs.python.org
Tue Feb 14 19:51:41 EST 2017
Matthias Bussonnier added the comment:
I'm unsure I understand changing only the default __str__() method. You will anyway have to format the message differently depending on whether you raise from a from-import or a from-import-* or any other locations.
AFAIU you "just" need the following
- PyErr_SetImportError(PyUnicode_FromFormat("cannot import name %R", name), pkgname, pkgpath);
+ PyErr_SetImportError(
+ PyUnicode_FromFormat("cannot import name %R from %R (%S)",
+ name, pkgname, pkgpath),
+ pkgname, pkgpath);
To use Barry format (though keeping quotes around identifiers to match current behavior).
(And similar if path is null).
I'm unsure if you meant to provide a set of "format-template" to ImportError that are guarantied to be called with format(name=..., path=...) but I doubt it.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29546>
_______________________________________
More information about the Python-bugs-list
mailing list