Skip to content
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

pkg_resources: Remove type-only _Importer class #11512

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions stubs/setuptools/pkg_resources/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import importlib.abc
import types
import zipimport
from _typeshed import Incomplete
from abc import ABCMeta
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
from io import BytesIO
from pkgutil import get_importer as get_importer
from re import Pattern
from typing import IO, Any, ClassVar, Literal, Protocol, TypeVar, overload
from typing_extensions import Self, TypeAlias
Expand All @@ -18,8 +17,10 @@ _InstallerType: TypeAlias = Callable[[Requirement], Distribution | None]
_EPDistType: TypeAlias = Distribution | Requirement | str
_MetadataType: TypeAlias = IResourceProvider | None
_PkgReqType: TypeAlias = str | Requirement
_DistFinderType: TypeAlias = Callable[[_Importer, str, bool], Generator[Distribution, None, None]]
_NSHandlerType: TypeAlias = Callable[[_Importer, str, str, types.ModuleType], str]
_ModuleLike: TypeAlias = object | types.ModuleType # Any object that optionally has __loader__ or __file__, usually a module
_ProviderFactoryType: TypeAlias = Callable[[_ModuleLike], IResourceProvider]
_DistFinderType: TypeAlias = Callable[[_T, str, bool], Iterable[Distribution]]
_NSHandlerType: TypeAlias = Callable[[_T, str, str, types.ModuleType], str | None]
Copy link
Collaborator Author

@Avasam Avasam Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it wasn't for the find_nothing method that returns an empty tuple, this would be correct in returning a Generator.
https://github.com/pypa/setuptools/blob/8c45d6e445a8ca5f5a1fd724a80a5c418fe36780/pkg_resources/__init__.py#L2092-L2093

xref pypa/setuptools#4249


def declare_namespace(packageName: str) -> None: ...
def fixup_namespace_packages(path_item: str, parent=None) -> None: ...
Expand Down Expand Up @@ -211,11 +212,9 @@ class ExtractionError(Exception):
cache_path: str
original_error: Exception

class _Importer(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader, metaclass=ABCMeta): ...

def register_finder(importer_type: type, distribution_finder: _DistFinderType) -> None: ...
def register_loader_type(loader_type: type, provider_factory: Callable[[types.ModuleType], IResourceProvider]) -> None: ...
def register_namespace_handler(importer_type: type, namespace_handler: _NSHandlerType) -> None: ...
def register_finder(importer_type: type[_T], distribution_finder: _DistFinderType[_T]) -> None: ...
def register_loader_type(loader_type: type[_ModuleLike], provider_factory: _ProviderFactoryType) -> None: ...
def register_namespace_handler(importer_type: type[_T], namespace_handler: _NSHandlerType[_T]) -> None: ...

class IResourceProvider(IMetadataProvider, Protocol):
def get_resource_filename(self, manager: ResourceManager, resource_name): ...
Expand All @@ -234,7 +233,7 @@ class NullProvider:
loader: types._LoaderProtocol | None
module_path: str | None

def __init__(self, module) -> None: ...
def __init__(self, module: _ModuleLike) -> None: ...
def get_resource_filename(self, manager: ResourceManager, resource_name) -> str: ...
def get_resource_stream(self, manager: ResourceManager, resource_name) -> BytesIO: ...
def get_resource_string(self, manager: ResourceManager, resource_name): ...
Expand Down Expand Up @@ -353,7 +352,6 @@ def get_platform() -> str: ...
def get_supported_platform() -> str: ...
def compatible_platforms(provided: str | None, required: str | None) -> bool: ...
def get_default_cache() -> str: ...
def get_importer(path_item: str) -> _Importer: ...
def ensure_directory(path: str) -> None: ...
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
def normalize_path(filename: str) -> str: ...

Expand Down
Loading