From f73efcc9291e69304522c696a4b5433ab2458acc Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 28 Nov 2023 15:48:34 -0500 Subject: [PATCH] Mark interfaces as Protocols and add missing `self` argument --- newsfragments/4144.bugfix.rst | 1 + pkg_resources/__init__.py | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 newsfragments/4144.bugfix.rst diff --git a/newsfragments/4144.bugfix.rst b/newsfragments/4144.bugfix.rst new file mode 100644 index 0000000000..9c4709b737 --- /dev/null +++ b/newsfragments/4144.bugfix.rst @@ -0,0 +1 @@ +Explicitely marked as ``Protocol`` and fixed missing ``self`` argument in interfaces ``pkg_resources.IMetadataProvider`` and ``pkg_resources.IResourceProvider`` -- by :user:`Avasam` diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index ab6afe955d..211b7561c9 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -23,6 +23,7 @@ import time import re import types +from typing import Protocol import zipfile import zipimport import warnings @@ -546,54 +547,54 @@ def get_entry_info(dist, group, name): return get_distribution(dist).get_entry_info(group, name) -class IMetadataProvider: - def has_metadata(name): +class IMetadataProvider(Protocol): + def has_metadata(self, name): """Does the package's distribution contain the named metadata?""" - def get_metadata(name): + def get_metadata(self, name): """The named metadata resource as a string""" - def get_metadata_lines(name): + def get_metadata_lines(self, name): """Yield named metadata resource as list of non-blank non-comment lines Leading and trailing whitespace is stripped from each line, and lines with ``#`` as the first non-blank character are omitted.""" - def metadata_isdir(name): + def metadata_isdir(self, name): """Is the named metadata a directory? (like ``os.path.isdir()``)""" - def metadata_listdir(name): + def metadata_listdir(self, name): """List of metadata names in the directory (like ``os.listdir()``)""" - def run_script(script_name, namespace): + def run_script(self, script_name, namespace): """Execute the named script in the supplied namespace dictionary""" -class IResourceProvider(IMetadataProvider): +class IResourceProvider(IMetadataProvider, Protocol): """An object that provides access to package resources""" - def get_resource_filename(manager, resource_name): + def get_resource_filename(self, manager, resource_name): """Return a true filesystem path for `resource_name` `manager` must be an ``IResourceManager``""" - def get_resource_stream(manager, resource_name): + def get_resource_stream(self, manager, resource_name): """Return a readable file-like object for `resource_name` `manager` must be an ``IResourceManager``""" - def get_resource_string(manager, resource_name): + def get_resource_string(self, manager, resource_name): """Return a string containing the contents of `resource_name` `manager` must be an ``IResourceManager``""" - def has_resource(resource_name): + def has_resource(self, resource_name): """Does the package contain the named resource?""" - def resource_isdir(resource_name): + def resource_isdir(self, resource_name): """Is the named resource a directory? (like ``os.path.isdir()``)""" - def resource_listdir(resource_name): + def resource_listdir(self, resource_name): """List of resource names in the directory (like ``os.listdir()``)"""