diff --git a/Lib/importlib/_abc.py b/Lib/importlib/_abc.py index fb5ec727cea6e4..ea50a652298ed7 100644 --- a/Lib/importlib/_abc.py +++ b/Lib/importlib/_abc.py @@ -1,9 +1,10 @@ """Subset of importlib.abc used to reduce importlib.util imports.""" from . import _bootstrap -import abc +from typing import Protocol, runtime_checkable -class Loader(metaclass=abc.ABCMeta): +@runtime_checkable +class Loader(Protocol): """Abstract base class for import loaders.""" diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index 97d5afa3001930..116766c7add4ea 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -29,7 +29,8 @@ def _register(abstract_cls, *classes): abstract_cls.register(frozen_cls) -class Finder(metaclass=abc.ABCMeta): +@runtime_checkable +class Finder(Protocol): """Legacy abstract base class for import finders. @@ -297,7 +298,8 @@ def set_data(self, path, data): _register(SourceLoader, machinery.SourceFileLoader) -class ResourceReader(metaclass=abc.ABCMeta): +@runtime_checkable +class ResourceReader(Protocol): """Abstract base class to provide resource-reading support. diff --git a/Misc/NEWS.d/next/Library/2020-06-30-14-55-59.bpo-38782.pbxiZV.rst b/Misc/NEWS.d/next/Library/2020-06-30-14-55-59.bpo-38782.pbxiZV.rst new file mode 100644 index 00000000000000..db6e330f0cc05b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-30-14-55-59.bpo-38782.pbxiZV.rst @@ -0,0 +1 @@ +Use :class:`typing.Protocol` in the :mod:`importlib.abc` module.