-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Mark interfaces as Protocols and add missing self
argument
#4144
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import time | ||
import re | ||
import types | ||
from typing import Protocol | ||
import zipfile | ||
import zipimport | ||
import warnings | ||
|
@@ -544,54 +545,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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Today I learned about extending protocols. Nice work. |
||
"""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()``)""" | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea if these protocols are used anywhere (such as with Zope), but I suspect not. If this change ends up causing unexpected disruption, we may have to back it out. Thanks for making it a separate PR.