Skip to content

Commit

Permalink
Mark interfaces as Protocols and add missing self argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Nov 28, 2023
1 parent 382e617 commit 2f7156d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions newsfragments/4144.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Explicitely marked as ``Protocol`` and fixed missing ``self`` argument in interfaces `pkg_resources.IMetadataProvider` and `pkg_resources.IResourceProvider` -- by :user:`Avasam`
29 changes: 15 additions & 14 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import time
import re
import types
from typing import Protocol
import zipfile
import zipimport
import warnings
Expand Down Expand Up @@ -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()``)"""


Expand Down

0 comments on commit 2f7156d

Please sign in to comment.