Skip to content

Commit 04a6bfe

Browse files
authored
Merge pull request #4144 from Avasam/pkg_resources-invalid-protocols
Mark interfaces as Protocols and add missing `self` argument
2 parents 0ad3a93 + 2ba6173 commit 04a6bfe

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

newsfragments/4144.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Explicitely marked as ``Protocol`` and fixed missing ``self`` argument in interfaces ``pkg_resources.IMetadataProvider`` and ``pkg_resources.IResourceProvider`` -- by :user:`Avasam`

pkg_resources/__init__.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import time
2828
import re
2929
import types
30+
from typing import Protocol
3031
import zipfile
3132
import zipimport
3233
import warnings
@@ -529,54 +530,54 @@ def get_entry_info(dist, group, name):
529530
return get_distribution(dist).get_entry_info(group, name)
530531

531532

532-
class IMetadataProvider:
533-
def has_metadata(name):
533+
class IMetadataProvider(Protocol):
534+
def has_metadata(self, name):
534535
"""Does the package's distribution contain the named metadata?"""
535536

536-
def get_metadata(name):
537+
def get_metadata(self, name):
537538
"""The named metadata resource as a string"""
538539

539-
def get_metadata_lines(name):
540+
def get_metadata_lines(self, name):
540541
"""Yield named metadata resource as list of non-blank non-comment lines
541542
542543
Leading and trailing whitespace is stripped from each line, and lines
543544
with ``#`` as the first non-blank character are omitted."""
544545

545-
def metadata_isdir(name):
546+
def metadata_isdir(self, name):
546547
"""Is the named metadata a directory? (like ``os.path.isdir()``)"""
547548

548-
def metadata_listdir(name):
549+
def metadata_listdir(self, name):
549550
"""List of metadata names in the directory (like ``os.listdir()``)"""
550551

551-
def run_script(script_name, namespace):
552+
def run_script(self, script_name, namespace):
552553
"""Execute the named script in the supplied namespace dictionary"""
553554

554555

555-
class IResourceProvider(IMetadataProvider):
556+
class IResourceProvider(IMetadataProvider, Protocol):
556557
"""An object that provides access to package resources"""
557558

558-
def get_resource_filename(manager, resource_name):
559+
def get_resource_filename(self, manager, resource_name):
559560
"""Return a true filesystem path for `resource_name`
560561
561562
`manager` must be an ``IResourceManager``"""
562563

563-
def get_resource_stream(manager, resource_name):
564+
def get_resource_stream(self, manager, resource_name):
564565
"""Return a readable file-like object for `resource_name`
565566
566567
`manager` must be an ``IResourceManager``"""
567568

568-
def get_resource_string(manager, resource_name):
569+
def get_resource_string(self, manager, resource_name):
569570
"""Return a string containing the contents of `resource_name`
570571
571572
`manager` must be an ``IResourceManager``"""
572573

573-
def has_resource(resource_name):
574+
def has_resource(self, resource_name):
574575
"""Does the package contain the named resource?"""
575576

576-
def resource_isdir(resource_name):
577+
def resource_isdir(self, resource_name):
577578
"""Is the named resource a directory? (like ``os.path.isdir()``)"""
578579

579-
def resource_listdir(resource_name):
580+
def resource_listdir(self, resource_name):
580581
"""List of resource names in the directory (like ``os.listdir()``)"""
581582

582583

0 commit comments

Comments
 (0)