diff options
author | Ngalim Siregar <ngalim.siregar@gmail.com> | 2019-08-03 05:46:02 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-08-03 05:46:02 (GMT) |
commit | c5fa44944ee0a31a12b9a70776c7cb56c4dc39a2 (patch) | |
tree | a0cbe2dbb223339419432483b9c893654f06100c /Doc/whatsnew | |
parent | 8e568ef266a2805f9a6042003723d9c050830461 (diff) | |
download | cpython-c5fa44944ee0a31a12b9a70776c7cb56c4dc39a2.zip cpython-c5fa44944ee0a31a12b9a70776c7cb56c4dc39a2.tar.gz cpython-c5fa44944ee0a31a12b9a70776c7cb56c4dc39a2.tar.bz2 |
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
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.9.rst | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index 273fd2b..61d9e74 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -75,6 +75,12 @@ New Features Other Language Changes ====================== +* :func:`builtins.__import__` now raises :exc:`ImportError` instead of + :exc:`ValueError` as used to occur when a relative import went past + its top-level package. + (Contributed by Ngalim Siregar in :issue:`37444`.) + + * Python now gets the absolute path of the script filename specified on the command line (ex: ``python3 script.py``): the ``__file__`` attribute of the ``__main__`` module, ``sys.argv[0]`` and ``sys.path[0]`` become an @@ -118,6 +124,13 @@ pprint :mod:`pprint` can now pretty-print :class:`types.SimpleNamespace`. (Contributed by Carl Bordum Hansen in :issue:`37376`.) +importlib +--------- + +To improve consistency with import statements, :func:`importlib.util.resolve_name` +now raises :exc:`ImportError` instead of :exc:`ValueError` for invalid relative +import attempts. +(Contributed by Ngalim Siregar in :issue:`37444`.) Optimizations ============= @@ -180,4 +193,11 @@ Porting to Python 3.9 This section lists previously described changes and other bugfixes that may require changes to your code. +Changes in the Python API +------------------------- +* :func:`builtins.__import__` and :func:`importlib.util.resolve_name` now raise + :exc:`ImportError` where it previously raised :exc:`ValueError`. Callers + catching the specific exception type and supporting both Python 3.9 and + earlier versions will need to catch both: + ``except (ImportError, ValueError):`` |