summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2018-03-24 10:39:36 (GMT)
committerGitHub <noreply@github.com>2018-03-24 10:39:36 (GMT)
commitd8b291a74284307610946f1b5801aa95d7f1e052 (patch)
tree617813bb9a48cc4af48cc8b9c0cc3c79694fa33c /Python
parent5cbb84106efefd200933aa31e22abf39267d2557 (diff)
downloadcpython-d8b291a74284307610946f1b5801aa95d7f1e052.zip
cpython-d8b291a74284307610946f1b5801aa95d7f1e052.tar.gz
cpython-d8b291a74284307610946f1b5801aa95d7f1e052.tar.bz2
bpo-32932: More revealing error message when non-str objects in __all__ (GH-5848)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 14603d3..d18a284 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4837,6 +4837,7 @@ import_all_from(PyObject *locals, PyObject *v)
{
_Py_IDENTIFIER(__all__);
_Py_IDENTIFIER(__dict__);
+ _Py_IDENTIFIER(__name__);
PyObject *all, *dict, *name, *value;
int skip_leading_underscores = 0;
int pos, err;
@@ -4869,7 +4870,32 @@ import_all_from(PyObject *locals, PyObject *v)
PyErr_Clear();
break;
}
- if (skip_leading_underscores && PyUnicode_Check(name)) {
+ if (!PyUnicode_Check(name)) {
+ PyObject *modname = _PyObject_GetAttrId(v, &PyId___name__);
+ if (modname == NULL) {
+ Py_DECREF(name);
+ err = -1;
+ break;
+ }
+ if (!PyUnicode_Check(modname)) {
+ PyErr_Format(PyExc_TypeError,
+ "module __name__ must be a string, not %.100s",
+ Py_TYPE(modname)->tp_name);
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "%s in %U.%s must be str, not %.100s",
+ skip_leading_underscores ? "Key" : "Item",
+ modname,
+ skip_leading_underscores ? "__dict__" : "__all__",
+ Py_TYPE(name)->tp_name);
+ }
+ Py_DECREF(modname);
+ Py_DECREF(name);
+ err = -1;
+ break;
+ }
+ if (skip_leading_underscores) {
if (PyUnicode_READY(name) == -1) {
Py_DECREF(name);
err = -1;