@@ -36,7 +36,7 @@ implement import semantics.
3636
3737When a module is first imported, Python searches for the module and if found,
3838it creates a module object [#fnmo ]_, initializing it. If the named module
39- cannot be found, an :exc: `ImportError ` is raised. Python implements various
39+ cannot be found, an :exc: `ModuleNotFoundError ` is raised. Python implements various
4040strategies to search for the named module when the import machinery is
4141invoked. These strategies can be modified and extended by using various hooks
4242described in the sections below.
@@ -167,7 +167,7 @@ arguments to the :keyword:`import` statement, or from the parameters to the
167167This name will be used in various phases of the import search, and it may be
168168the dotted path to a submodule, e.g. ``foo.bar.baz ``. In this case, Python
169169first tries to import ``foo ``, then ``foo.bar ``, and finally ``foo.bar.baz ``.
170- If any of the intermediate imports fail, an :exc: `ImportError ` is raised.
170+ If any of the intermediate imports fail, an :exc: `ModuleNotFoundError ` is raised.
171171
172172
173173The module cache
@@ -186,15 +186,15 @@ object.
186186During import, the module name is looked up in :data: `sys.modules ` and if
187187present, the associated value is the module satisfying the import, and the
188188process completes. However, if the value is ``None ``, then an
189- :exc: `ImportError ` is raised. If the module name is missing, Python will
189+ :exc: `ModuleNotFoundError ` is raised. If the module name is missing, Python will
190190continue searching for the module.
191191
192192:data: `sys.modules ` is writable. Deleting a key may not destroy the
193193associated module (as other modules may hold references to it),
194194but it will invalidate the cache entry for the named module, causing
195195Python to search anew for the named module upon its next
196196import. The key can also be assigned to ``None ``, forcing the next import
197- of the module to result in an :exc: `ImportError `.
197+ of the module to result in an :exc: `ModuleNotFoundError `.
198198
199199Beware though, as if you keep a reference to the module object,
200200invalidate its cache entry in :data: `sys.modules `, and then re-import the
@@ -288,8 +288,8 @@ the named module or not.
288288If the meta path finder knows how to handle the named module, it returns a
289289spec object. If it cannot handle the named module, it returns ``None ``. If
290290:data: `sys.meta_path ` processing reaches the end of its list without returning
291- a spec, then an :exc: `ImportError ` is raised. Any other exceptions raised
292- are simply propagated up, aborting the import process.
291+ a spec, then a :exc: `ModuleNotFoundError ` is raised. Any other exceptions
292+ raised are simply propagated up, aborting the import process.
293293
294294The :meth: `~importlib.abc.MetaPathFinder.find_spec() ` method of meta path
295295finders is called with two or three arguments. The first is the fully
@@ -298,9 +298,9 @@ The second argument is the path entries to use for the module search. For
298298top-level modules, the second argument is ``None ``, but for submodules or
299299subpackages, the second argument is the value of the parent package's
300300``__path__ `` attribute. If the appropriate ``__path__ `` attribute cannot
301- be accessed, an :exc: `ImportError ` is raised. The third argument is an
302- existing module object that will be the target of loading later. The
303- import system passes in a target module only during reload.
301+ be accessed, an :exc: `ModuleNotFoundError ` is raised. The third argument
302+ is an existing module object that will be the target of loading later.
303+ The import system passes in a target module only during reload.
304304
305305The meta path may be traversed multiple times for a single import request.
306306For example, assuming none of the modules involved has already been cached,
@@ -887,7 +887,7 @@ import statements within that module.
887887
888888To selectively prevent import of some modules from a hook early on the
889889meta path (rather than disabling the standard import system entirely),
890- it is sufficient to raise :exc: `ImportError ` directly from
890+ it is sufficient to raise :exc: `ModuleNoFoundError ` directly from
891891:meth: `~importlib.abc.MetaPathFinder.find_spec ` instead of returning
892892``None ``. The latter indicates that the meta path search should continue,
893893while raising an exception terminates it immediately.
0 commit comments