summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2021-04-06 15:56:57 (GMT)
committerGitHub <noreply@github.com>2021-04-06 15:56:57 (GMT)
commit57c6cb5100d19a0e0218c77d887c3c239c9ce435 (patch)
tree8e193c0bc12f476821639c8363d280ef9d604271 /Lib/importlib
parentefccff9ac84009ef48e8cb22548ce80940f76533 (diff)
downloadcpython-57c6cb5100d19a0e0218c77d887c3c239c9ce435.zip
cpython-57c6cb5100d19a0e0218c77d887c3c239c9ce435.tar.gz
cpython-57c6cb5100d19a0e0218c77d887c3c239c9ce435.tar.bz2
bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169)
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/__init__.py4
-rw-r--r--Lib/importlib/_bootstrap.py6
-rw-r--r--Lib/importlib/_bootstrap_external.py14
-rw-r--r--Lib/importlib/abc.py20
4 files changed, 37 insertions, 7 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
index 03ff714..a510f08 100644
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -78,8 +78,8 @@ def find_loader(name, path=None):
This function is deprecated in favor of importlib.util.find_spec().
"""
- warnings.warn('Deprecated since Python 3.4. '
- 'Use importlib.util.find_spec() instead.',
+ warnings.warn('Deprecated since Python 3.4 and slated for removal in '
+ 'Python 3.10; use importlib.util.find_spec() instead',
DeprecationWarning, stacklevel=2)
try:
loader = sys.modules[name].__loader__
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index ab52e77..527bc9c 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -761,6 +761,9 @@ class BuiltinImporter:
This method is deprecated. Use find_spec() instead.
"""
+ _warnings.warn("BuiltinImporter.find_module() is deprecated and "
+ "slated for removal in Python 3.12; use find_spec() instead",
+ DeprecationWarning)
spec = cls.find_spec(fullname, path)
return spec.loader if spec is not None else None
@@ -834,6 +837,9 @@ class FrozenImporter:
This method is deprecated. Use find_spec() instead.
"""
+ _warnings.warn("FrozenImporter.find_module() is deprecated and "
+ "slated for removal in Python 3.12; use find_spec() instead",
+ DeprecationWarning)
return cls if _imp.is_frozen(fullname) else None
@staticmethod
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index d351ee0..34f554a 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -533,6 +533,9 @@ def _find_module_shim(self, fullname):
This method is deprecated in favor of finder.find_spec().
"""
+ _warnings.warn("find_module() is deprecated and "
+ "slated for removal in Python 3.12; use find_spec() instead",
+ DeprecationWarning)
# Call find_loader(). If it returns a string (indicating this
# is a namespace package portion), generate a warning and
# return None.
@@ -801,9 +804,12 @@ class WindowsRegistryFinder:
def find_module(cls, fullname, path=None):
"""Find module named in the registry.
- This method is deprecated. Use exec_module() instead.
+ This method is deprecated. Use find_spec() instead.
"""
+ _warnings.warn("WindowsRegistryFinder.find_module() is deprecated and "
+ "slated for removal in Python 3.12; use find_spec() instead",
+ DeprecationWarning)
spec = cls.find_spec(fullname, path)
if spec is not None:
return spec.loader
@@ -1404,6 +1410,9 @@ class PathFinder:
This method is deprecated. Use find_spec() instead.
"""
+ _warnings.warn("PathFinder.find_module() is deprecated and "
+ "slated for removal in Python 3.12; use find_spec() instead",
+ DeprecationWarning)
spec = cls.find_spec(fullname, path)
if spec is None:
return None
@@ -1459,6 +1468,9 @@ class FileFinder:
This method is deprecated. Use find_spec() instead.
"""
+ _warnings.warn("FileFinder.find_loader() is deprecated and "
+ "slated for removal in Python 3.12; use find_spec() instead",
+ DeprecationWarning)
spec = self.find_spec(fullname)
if spec is None:
return None, []
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index 4be51e2..0b4a3f8 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -41,15 +41,27 @@ class Finder(metaclass=abc.ABCMeta):
Deprecated since Python 3.3
"""
+ def __init__(self):
+ warnings.warn("the Finder ABC is deprecated and "
+ "slated for removal in Python 3.12; use MetaPathFinder "
+ "or PathEntryFinder instead",
+ DeprecationWarning)
+
@abc.abstractmethod
def find_module(self, fullname, path=None):
"""An abstract method that should find a module.
The fullname is a str and the optional path is a str or None.
Returns a Loader object or None.
"""
+ warnings.warn("importlib.abc.Finder along with its find_module() "
+ "method are deprecated and "
+ "slated for removal in Python 3.12; use "
+ "MetaPathFinder.find_spec() or "
+ "PathEntryFinder.find_spec() instead",
+ DeprecationWarning)
-class MetaPathFinder(Finder):
+class MetaPathFinder(metaclass=abc.ABCMeta):
"""Abstract base class for import finders on sys.meta_path."""
@@ -68,8 +80,8 @@ class MetaPathFinder(Finder):
"""
warnings.warn("MetaPathFinder.find_module() is deprecated since Python "
- "3.4 in favor of MetaPathFinder.find_spec() "
- "(available since 3.4)",
+ "3.4 in favor of MetaPathFinder.find_spec() and is "
+ "slated for removal in Python 3.12",
DeprecationWarning,
stacklevel=2)
if not hasattr(self, 'find_spec'):
@@ -86,7 +98,7 @@ _register(MetaPathFinder, machinery.BuiltinImporter, machinery.FrozenImporter,
machinery.PathFinder, machinery.WindowsRegistryFinder)
-class PathEntryFinder(Finder):
+class PathEntryFinder(metaclass=abc.ABCMeta):
"""Abstract base class for path entry finders used by PathFinder."""