@@ -37,7 +37,7 @@ use the standard import system.
3737
3838When a module is first imported, Python searches for the module and if found,
3939it creates a module object [#fnmo ]_, initializing it. If the named module
40- cannot be found, an :exc: `ModuleNotFoundError ` is raised. Python implements various
40+ cannot be found, an :exc: `ImportError ` is raised. Python implements various
4141strategies to search for the named module when the import machinery is
4242invoked. These strategies can be modified and extended by using various hooks
4343described in the sections below.
@@ -168,7 +168,7 @@ arguments to the :keyword:`import` statement, or from the parameters to the
168168This name will be used in various phases of the import search, and it may be
169169the dotted path to a submodule, e.g. ``foo.bar.baz ``. In this case, Python
170170first tries to import ``foo ``, then ``foo.bar ``, and finally ``foo.bar.baz ``.
171- If any of the intermediate imports fail, an :exc: `ModuleNotFoundError ` is raised.
171+ If any of the intermediate imports fail, an :exc: `ImportError ` is raised.
172172
173173
174174The module cache
@@ -187,15 +187,15 @@ object.
187187During import, the module name is looked up in :data: `sys.modules ` and if
188188present, the associated value is the module satisfying the import, and the
189189process completes. However, if the value is ``None ``, then an
190- :exc: `ModuleNotFoundError ` is raised. If the module name is missing, Python will
190+ :exc: `ImportError ` is raised. If the module name is missing, Python will
191191continue searching for the module.
192192
193193:data: `sys.modules ` is writable. Deleting a key may not destroy the
194194associated module (as other modules may hold references to it),
195195but it will invalidate the cache entry for the named module, causing
196196Python to search anew for the named module upon its next
197197import. The key can also be assigned to ``None ``, forcing the next import
198- of the module to result in an :exc: `ModuleNotFoundError `.
198+ of the module to result in an :exc: `ImportError `.
199199
200200Beware though, as if you keep a reference to the module object,
201201invalidate its cache entry in :data: `sys.modules `, and then re-import the
@@ -284,7 +284,7 @@ handle the named module or not.
284284If the meta path finder knows how to handle the named module, it returns a
285285loader object. If it cannot handle the named module, it returns ``None ``. If
286286:data: `sys.meta_path ` processing reaches the end of its list without returning
287- a loader, then an :exc: `ModuleNotFoundError ` is raised. Any other exceptions raised
287+ a loader, then an :exc: `ImportError ` is raised. Any other exceptions raised
288288are simply propagated up, aborting the import process.
289289
290290The :meth: `find_module() ` method of meta path finders is called with two
@@ -647,7 +647,7 @@ import statements within that module.
647647
648648To selectively prevent import of some modules from a hook early on the
649649meta path (rather than disabling the standard import system entirely),
650- it is sufficient to raise :exc: `ModuleNotFoundError ` directly from
650+ it is sufficient to raise :exc: `ImportError ` directly from
651651:meth: `find_module ` instead of returning ``None ``. The latter indicates
652652that the meta path search should continue. while raising an exception
653653terminates it immediately.
0 commit comments