bpo-37444: Update differing exception between builtins and importlib (GH-14869)

Imports now raise `TypeError` instead of `ValueError` for relative import failures. This makes things consistent between `builtins.__import__` and `importlib.__import__` as well as using a more natural import for the failure.


https://bugs.python.org/issue37444



Automerge-Triggered-By: @brettcannon
This commit is contained in:
Ngalim Siregar 2019-08-03 12:46:02 +07:00 committed by Miss Islington (bot)
parent 8e568ef266
commit c5fa44944e
9 changed files with 134 additions and 108 deletions

View file

@ -1671,7 +1671,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level
goto error;
}
else if (last_dot == -1) {
_PyErr_SetString(tstate, PyExc_ValueError,
_PyErr_SetString(tstate, PyExc_ImportError,
"attempted relative import beyond top-level "
"package");
goto error;