bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169)
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index 6515cdb..50297e0 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -257,6 +257,10 @@
Returns ``None`` when called instead of raising
:exc:`NotImplementedError`.
+ .. deprecated:: 3.10
+ Implement :meth:`MetaPathFinder.find_spec` or
+ :meth:`PathEntryFinder.find_spec` instead.
+
.. class:: MetaPathFinder
@@ -265,6 +269,9 @@
.. versionadded:: 3.3
+ .. versionchanged:: 3.10
+ No longer a subclass of :class:`Finder`.
+
.. method:: find_spec(fullname, path, target=None)
An abstract method for finding a :term:`spec <module spec>` for
@@ -313,11 +320,13 @@
An abstract base class representing a :term:`path entry finder`. Though
it bears some similarities to :class:`MetaPathFinder`, ``PathEntryFinder``
is meant for use only within the path-based import subsystem provided
- by :class:`PathFinder`. This ABC is a subclass of :class:`Finder` for
- compatibility reasons only.
+ by :class:`importlib.machinery.PathFinder`.
.. versionadded:: 3.3
+ .. versionchanged:: 3.10
+ No longer a subclass of :class:`Finder`.
+
.. method:: find_spec(fullname, target=None)
An abstract method for finding a :term:`spec <module spec>` for
@@ -363,7 +372,8 @@
.. method:: invalidate_caches()
An optional method which, when called, should invalidate any internal
- cache used by the finder. Used by :meth:`PathFinder.invalidate_caches`
+ cache used by the finder. Used by
+ :meth:`importlib.machinery.PathFinder.invalidate_caches`
when invalidating the caches of all cached finders.
@@ -1193,6 +1203,9 @@
Attempt to find the loader to handle *fullname* within :attr:`path`.
+ .. deprecated:: 3.10
+ Use :meth:`find_spec` instead.
+
.. method:: invalidate_caches()
Clear out the internal cache.
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 7295015..453a1b4 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -1062,6 +1062,39 @@
:func:`importlib.util.spec_from_loader` to help in porting.
(Contributed by Brett Cannon in :issue:`43672`.)
+* The various implementations of
+ :meth:`importlib.abc.MetaPathFinder.find_module` (
+ :meth:`importlib.machinery.BuiltinImporter.find_module`,
+ :meth:`importlib.machinery.FrozenImporter.find_module`,
+ :meth:`importlib.machinery.WindowsRegistryFinder.find_module`,
+ :meth:`importlib.machinery.PathFinder.find_module`,
+ :meth:`importlib.abc.MetaPathFinder.find_module`),
+ :meth:`importlib.abc.PathEntryFinder.find_module` (
+ :meth:`importlib.machinery.FileFinder.find_module`,
+ ), and
+ :meth:`importlib.abc.PathEntryFinder.find_loader` (
+ :meth:`importlib.machinery.FileFinder.find_loader`
+ ) now raise :exc:`DeprecationWarning` and are slated for removal in
+ Python 3.12 (previously they were documented as deprecated in Python 3.4).
+ (Contributed by Brett Cannon in :issue:`42135`.)
+
+* :class:`importlib.abc.Finder` is deprecated (including its sole method,
+ :meth:`~importlib.abc.Finder.find_module`). Both
+ :class:`importlib.abc.MetaPathFinder` and :class:`importlib.abc.PathEntryFinder`
+ no longer inherit from the class. Users should inherit from one of these two
+ classes as appropriate instead.
+ (Contributed by Brett Cannon in :issue:`42135`.)
+
+* The deprecations of :mod:`imp`, :func:`importlib.find_loader`,
+ :func:`importlib.util.set_package_wrapper`,
+ :func:`importlib.util.set_loader_wrapper`,
+ :func:`importlib.util.module_for_loader`,
+ :class:`pkgutil.ImpImporter`, and
+ :class:`pkgutil.ImpLoader` have all been updated to list Python 3.12 as the
+ slated version of removal (they began raising :exc:`DeprecationWarning` in
+ previous versions of Python).
+ (Contributed by Brett Cannon in :issue:`43720`.)
+
* The import system now uses the ``__spec__`` attribute on modules before
falling back on :meth:`~importlib.abc.Loader.module_repr` for a module's
``__repr__()`` method. Removal of the use of ``module_repr()`` is scheduled