From 2f7997894c3c883f4ee0f46167de9e49d10d4e65 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Tue, 30 Jun 2020 14:57:12 -0600 Subject: [PATCH] bpo-38782: Use typing.Protocol in the importlib.abc module --- Lib/importlib/_abc.py | 5 +++-- Lib/importlib/abc.py | 6 ++++-- .../next/Library/2020-06-30-14-55-59.bpo-38782.pbxiZV.rst | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-06-30-14-55-59.bpo-38782.pbxiZV.rst 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.