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
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index 65a6850..8be6172 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -1433,13 +1433,18 @@
``importlib.util.resolve_name('sys', __package__)`` without doing a
check to see if the **package** argument is needed.
- :exc:`ValueError` is raised if **name** is a relative module name but
- package is a false value (e.g. ``None`` or the empty string).
- :exc:`ValueError` is also raised a relative name would escape its containing
+ :exc:`ImportError` is raised if **name** is a relative module name but
+ **package** is a false value (e.g. ``None`` or the empty string).
+ :exc:`ImportError` is also raised a relative name would escape its containing
package (e.g. requesting ``..bacon`` from within the ``spam`` package).
.. versionadded:: 3.3
+ .. versionchanged:: 3.9
+ To improve consistency with import statements, raise
+ :exc:`ImportError` instead of :exc:`ValueError` for invalid relative
+ import attempts.
+
.. function:: find_spec(name, package=None)
Find the :term:`spec <module spec>` for a module, optionally relative to