Skip to content

bpo-38782: Use typing.Protocol in the importlib.abc module #21245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/importlib/_abc.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand Down
6 changes: 4 additions & 2 deletions Lib/importlib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use :class:`typing.Protocol` in the :mod:`importlib.abc` module.