Skip to content

Commit 1edb3dc

Browse files
miss-islingtonncoghlan
authored andcommitted
bpo-35486: Note Py3.6 import system API requirement change (GH-11540) (GH-11588)
While the introduction of ModuleNotFoundError was fully backwards compatible on the import API consumer side, folks providing alternative implementations of `__import__` need to make an update to be forward compatible with clients that start relying on the new subclass. https://bugs.python.org/issue35486 (cherry picked from commit cee29b4) Co-authored-by: Nick Coghlan <[email protected]>
1 parent 7887c02 commit 1edb3dc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Doc/library/importlib.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,8 @@ Python 3.6 and newer for other parts of the code).
14881488
if spec is not None:
14891489
break
14901490
else:
1491-
raise ImportError(f'No module named {absolute_name!r}')
1491+
msg = f'No module named {absolute_name!r}'
1492+
raise ModuleNotFoundError(msg, name=absolute_name)
14921493
module = importlib.util.module_from_spec(spec)
14931494
spec.loader.exec_module(module)
14941495
sys.modules[absolute_name] = module

Doc/whatsnew/3.6.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,17 @@ Changes in the Python API
23282328
a :exc:`DeprecationWarning` in Python 3.6 and a :exc:`RuntimeError` in
23292329
Python 3.8.
23302330

2331+
* With the introduction of :exc:`ModuleNotFoundError`, import system consumers
2332+
may start expecting import system replacements to raise that more specific
2333+
exception when appropriate, rather than the less-specific :exc:`ImportError`.
2334+
To provide future compatibility with such consumers, implementors of
2335+
alternative import systems that completely replace :func:`__import__` will
2336+
need to update their implementations to raise the new subclass when a module
2337+
can't be found at all. Implementors of compliant plugins to the default
2338+
import system shouldn't need to make any changes, as the default import
2339+
system will raise the new subclass when appropriate.
2340+
2341+
23312342
Changes in the C API
23322343
--------------------
23332344

0 commit comments

Comments
 (0)