Skip to content

Commit 2f7156d

Browse files
committed
Mark interfaces as Protocols and add missing self argument
1 parent 382e617 commit 2f7156d

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
@@ -23,6 +23,7 @@
2323
import time
2424
import re
2525
import types
26+
from typing import Protocol
2627
import zipfile
2728
import zipimport
2829
import warnings
@@ -546,54 +547,54 @@ def get_entry_info(dist, group, name):
546547
return get_distribution(dist).get_entry_info(group, name)
547548

548549

549-
class IMetadataProvider:
550-
def has_metadata(name):
550+
class IMetadataProvider(Protocol):
551+
def has_metadata(self, name):
551552
"""Does the package's distribution contain the named metadata?"""
552553

553-
def get_metadata(name):
554+
def get_metadata(self, name):
554555
"""The named metadata resource as a string"""
555556

556-
def get_metadata_lines(name):
557+
def get_metadata_lines(self, name):
557558
"""Yield named metadata resource as list of non-blank non-comment lines
558559
559560
Leading and trailing whitespace is stripped from each line, and lines
560561
with ``#`` as the first non-blank character are omitted."""
561562

562-
def metadata_isdir(name):
563+
def metadata_isdir(self, name):
563564
"""Is the named metadata a directory? (like ``os.path.isdir()``)"""
564565

565-
def metadata_listdir(name):
566+
def metadata_listdir(self, name):
566567
"""List of metadata names in the directory (like ``os.listdir()``)"""
567568

568-
def run_script(script_name, namespace):
569+
def run_script(self, script_name, namespace):
569570
"""Execute the named script in the supplied namespace dictionary"""
570571

571572

572-
class IResourceProvider(IMetadataProvider):
573+
class IResourceProvider(IMetadataProvider, Protocol):
573574
"""An object that provides access to package resources"""
574575

575-
def get_resource_filename(manager, resource_name):
576+
def get_resource_filename(self, manager, resource_name):
576577
"""Return a true filesystem path for `resource_name`
577578
578579
`manager` must be an ``IResourceManager``"""
579580

580-
def get_resource_stream(manager, resource_name):
581+
def get_resource_stream(self, manager, resource_name):
581582
"""Return a readable file-like object for `resource_name`
582583
583584
`manager` must be an ``IResourceManager``"""
584585

585-
def get_resource_string(manager, resource_name):
586+
def get_resource_string(self, manager, resource_name):
586587
"""Return a string containing the contents of `resource_name`
587588
588589
`manager` must be an ``IResourceManager``"""
589590

590-
def has_resource(resource_name):
591+
def has_resource(self, resource_name):
591592
"""Does the package contain the named resource?"""
592593

593-
def resource_isdir(resource_name):
594+
def resource_isdir(self, resource_name):
594595
"""Is the named resource a directory? (like ``os.path.isdir()``)"""
595596

596-
def resource_listdir(resource_name):
597+
def resource_listdir(self, resource_name):
597598
"""List of resource names in the directory (like ``os.listdir()``)"""
598599

599600

0 commit comments

Comments
 (0)