From 426ad0bb1693884312a2c6fb5ff8319111f6fbb1 Mon Sep 17 00:00:00 2001 From: meowmeowcat <68463158+meowmeowmeowcat@users.noreply.github.com> Date: Tue, 10 Aug 2021 20:50:22 +0800 Subject: [PATCH 1/4] bpo-40899: Document exception raised when module cannot be imported --- Doc/library/functions.rst | 3 ++- Doc/library/importlib.rst | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 652e30c6088ad9..1dd06f611c1a1a 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1910,7 +1910,8 @@ are always available. They are listed here in alphabetical order. This is an advanced function that is not needed in everyday Python programming, unlike :func:`importlib.import_module`. - This function is invoked by the :keyword:`import` statement. It can be + This function is invoked by the :keyword:`import` statement. + If the module cannot be imported, :exc:`ImportError` is raised. It can be replaced (by importing the :mod:`builtins` module and assigning to ``builtins.__import__``) in order to change semantics of the :keyword:`!import` statement, but doing so is **strongly** discouraged as it diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst index b5ee7a6b9659af..e14baa7fa35d64 100644 --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -96,7 +96,7 @@ Functions specified in relative terms, then the *package* argument must be set to the name of the package which is to act as the anchor for resolving the package name (e.g. ``import_module('..mod', 'pkg.subpkg')`` will import - ``pkg.mod``). + ``pkg.mod``). If the module cannot be imported, :exc:`ImportError` is raised. The :func:`import_module` function acts as a simplifying wrapper around :func:`importlib.__import__`. This means all semantics of the function are From 5cf6217286313376ca0fa5e692623968e1e4b30b Mon Sep 17 00:00:00 2001 From: meowmeow Date: Thu, 24 Nov 2022 09:22:24 +0000 Subject: [PATCH 2/4] Update docs --- Doc/library/functions.rst | 6 ++++-- Doc/library/importlib.rst | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 1dd06f611c1a1a..efce943e5fb891 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1910,8 +1910,7 @@ are always available. They are listed here in alphabetical order. This is an advanced function that is not needed in everyday Python programming, unlike :func:`importlib.import_module`. - This function is invoked by the :keyword:`import` statement. - If the module cannot be imported, :exc:`ImportError` is raised. It can be + This function is invoked by the :keyword:`import` statement. It can be replaced (by importing the :mod:`builtins` module and assigning to ``builtins.__import__``) in order to change semantics of the :keyword:`!import` statement, but doing so is **strongly** discouraged as it @@ -1961,6 +1960,9 @@ are always available. They are listed here in alphabetical order. object, the names to import are retrieved and assigned to their respective names. + A :exc:`ImportError` exception can be raised if the module cannot be imported + successfully. + If you simply want to import a module (potentially within a package) by name, use :func:`importlib.import_module`. diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst index e14baa7fa35d64..18461d677b3652 100644 --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -96,7 +96,7 @@ Functions specified in relative terms, then the *package* argument must be set to the name of the package which is to act as the anchor for resolving the package name (e.g. ``import_module('..mod', 'pkg.subpkg')`` will import - ``pkg.mod``). If the module cannot be imported, :exc:`ImportError` is raised. + ``pkg.mod``). The :func:`import_module` function acts as a simplifying wrapper around :func:`importlib.__import__`. This means all semantics of the function are @@ -110,6 +110,9 @@ Functions need to call :func:`invalidate_caches` in order for the new module to be noticed by the import system. + A :exc:`ImportError` can be raised if the module cannot be imported + successfully. + .. versionchanged:: 3.3 Parent packages are automatically imported. From 1a962e346a4deedb94876fe44fe9a386ccc07931 Mon Sep 17 00:00:00 2001 From: Jason Lam Date: Thu, 24 Nov 2022 17:28:59 +0800 Subject: [PATCH 3/4] Update Doc/library/importlib.rst --- Doc/library/importlib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst index 708228c9819c51..c13ec4ad36e2ee 100644 --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -124,7 +124,7 @@ Functions need to call :func:`invalidate_caches` in order for the new module to be noticed by the import system. - A :exc:`ImportError` can be raised if the module cannot be imported + A :exc:`ImportError` exception can be raised if the module cannot be imported successfully. .. versionchanged:: 3.3 From c494ed665acbc3defbf0b26cb8289f23407e26df Mon Sep 17 00:00:00 2001 From: Jason Lam Date: Thu, 24 Nov 2022 19:00:41 +0800 Subject: [PATCH 4/4] Fix typo Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- Doc/library/functions.rst | 2 +- Doc/library/importlib.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 91c153cffa6033..8a621c03d9fe5a 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -2018,7 +2018,7 @@ are always available. They are listed here in alphabetical order. object, the names to import are retrieved and assigned to their respective names. - A :exc:`ImportError` exception can be raised if the module cannot be imported + An :exc:`ImportError` exception can be raised if the module cannot be imported successfully. If you simply want to import a module (potentially within a package) by name, diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst index c13ec4ad36e2ee..06cd62541db195 100644 --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -124,7 +124,7 @@ Functions need to call :func:`invalidate_caches` in order for the new module to be noticed by the import system. - A :exc:`ImportError` exception can be raised if the module cannot be imported + An :exc:`ImportError` exception can be raised if the module cannot be imported successfully. .. versionchanged:: 3.3