Skip to content

Commit cee29b4

Browse files
ncoghlanmiss-islington
authored andcommitted
bpo-35486: Note Py3.6 import system API requirement change (GH-11540)
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
1 parent 8c34956 commit cee29b4

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
@@ -1737,7 +1737,8 @@ Python 3.6 and newer for other parts of the code).
17371737
if spec is not None:
17381738
break
17391739
else:
1740-
raise ImportError(f'No module named {absolute_name!r}')
1740+
msg = f'No module named {absolute_name!r}'
1741+
raise ModuleNotFoundError(msg, name=absolute_name)
17411742
module = importlib.util.module_from_spec(spec)
17421743
spec.loader.exec_module(module)
17431744
sys.modules[absolute_name] = module

Doc/whatsnew/3.6.rst

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

2319+
* With the introduction of :exc:`ModuleNotFoundError`, import system consumers
2320+
may start expecting import system replacements to raise that more specific
2321+
exception when appropriate, rather than the less-specific :exc:`ImportError`.
2322+
To provide future compatibility with such consumers, implementors of
2323+
alternative import systems that completely replace :func:`__import__` will
2324+
need to update their implementations to raise the new subclass when a module
2325+
can't be found at all. Implementors of compliant plugins to the default
2326+
import system shouldn't need to make any changes, as the default import
2327+
system will raise the new subclass when appropriate.
2328+
2329+
23192330
Changes in the C API
23202331
--------------------
23212332

0 commit comments

Comments
 (0)