Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Doc/library/importlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,8 @@ Python 3.6 and newer for other parts of the code).
if spec is not None:
break
else:
raise ImportError(f'No module named {absolute_name!r}')
msg = f'No module named {absolute_name!r}'
raise ModuleNotFoundError(msg, name=absolute_name)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
sys.modules[absolute_name] = module
Expand Down
11 changes: 11 additions & 0 deletions Doc/whatsnew/3.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,17 @@ Changes in the Python API
a :exc:`DeprecationWarning` in Python 3.6 and a :exc:`RuntimeError` in
Python 3.8.

* With the introduction of :exc:`ModuleNotFoundError`, import system consumers
may start expecting import system replacements to raise that more specific
exception when appropriate, rather than the less-specific :exc:`ImportError`.
To provide future compatibility with such consumers, implementors of
alternative import systems that completely replace :func:`__import__` will
need to update their implementations to raise the new subclass when a module
can't be found at all. Implementors of compliant plugins to the default
import system shouldn't need to make any changes, as the default import
system will raise the new subclass when appropriate.


Changes in the C API
--------------------

Expand Down