diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index ad6ed0d28fa2..a8614a67dcb7 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -5,7 +5,7 @@ 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, Final, Literal, Protocol, TypeVar, overload, type_check_only +from typing import IO, Any, ClassVar, Final, Literal, NoReturn, Protocol, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias from zipfile import ZipInfo @@ -13,11 +13,12 @@ from ._vendored_packaging import requirements as packaging_requirements, version _T = TypeVar("_T") _D = TypeVar("_D", bound=Distribution) -_NestedStr: TypeAlias = str | Iterable[str | Iterable[Any]] +_NestedStr: TypeAlias = str | Iterable[str | Iterable[_NestedStr]] _InstallerType: TypeAlias = Callable[[Requirement], Distribution | None] _EPDistType: TypeAlias = Distribution | Requirement | str _MetadataType: TypeAlias = IResourceProvider | None _PkgReqType: TypeAlias = str | Requirement +_ResolvedEntryPoint: TypeAlias = Any # Can be any attribute in the module _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]] @@ -158,7 +159,7 @@ class Environment: def obtain(self, requirement: Requirement, installer: Callable[[Requirement], _T]) -> _T: ... def __iter__(self) -> Iterator[str]: ... def __iadd__(self, other: Distribution | Environment) -> Self: ... - def __add__(self, other: Distribution | Environment) -> Environment: ... + def __add__(self, other: Distribution | Environment) -> Self: ... AvailableDistributions = Environment @@ -178,7 +179,7 @@ class Requirement(packaging_requirements.Requirement): @staticmethod def parse(s: str | Iterable[str]) -> Requirement: ... -def load_entry_point(dist: _EPDistType, group: str, name: str) -> Any: ... +def load_entry_point(dist: _EPDistType, group: str, name: str) -> _ResolvedEntryPoint: ... @overload def get_entry_map(dist: _EPDistType, group: None = None) -> dict[str, dict[str, EntryPoint]]: ... @overload @@ -200,11 +201,13 @@ class EntryPoint: extras: tuple[str, ...] = (), dist: Distribution | None = None, ) -> None: ... - def load(self, require: bool = True, env: Environment | None = ..., installer: _InstallerType | None = ...) -> Any: ... - def resolve(self) -> Any: ... + def load( + self, require: bool = True, env: Environment | None = ..., installer: _InstallerType | None = ... + ) -> _ResolvedEntryPoint: ... + def resolve(self) -> _ResolvedEntryPoint: ... def require(self, env: Environment | None = None, installer: _InstallerType | None = None) -> None: ... @classmethod - def parse(cls, src: str, dist: Distribution | None = None) -> EntryPoint: ... + def parse(cls, src: str, dist: Distribution | None = None) -> Self: ... @classmethod def parse_group(cls, group: str, lines: str | Sequence[str], dist: Distribution | None = None) -> dict[str, EntryPoint]: ... @classmethod @@ -235,7 +238,7 @@ class ResourceManager: def resource_stream(self, package_or_requirement: _PkgReqType, resource_name: str) -> IO[bytes]: ... def resource_string(self, package_or_requirement: _PkgReqType, resource_name: str) -> bytes: ... def resource_listdir(self, package_or_requirement: _PkgReqType, resource_name: str) -> list[str]: ... - def extraction_error(self) -> None: ... + def extraction_error(self) -> NoReturn: ... def get_cache_path(self, archive_name: str, names: Iterable[str] = ()) -> str: ... def postprocess(self, tempname: str, filename: str) -> None: ... def set_extraction_path(self, path: str) -> None: ... @@ -267,25 +270,28 @@ class IMetadataProvider(Protocol): class ResolutionError(Exception): ... class DistributionNotFound(ResolutionError): + def __init__(self, req: Requirement, requirers: set[str] | None, /, *args: object) -> None: ... @property def req(self) -> Requirement: ... @property - def requirers(self) -> set[str]: ... + def requirers(self) -> set[str] | None: ... @property def requirers_str(self) -> str: ... def report(self) -> str: ... class VersionConflict(ResolutionError): + def __init__(self, dist: Distribution, req: Requirement, /, *args: object) -> None: ... @property - def dist(self) -> Any: ... + def dist(self) -> Distribution: ... @property - def req(self) -> Any: ... + def req(self) -> Requirement: ... def report(self) -> str: ... - def with_context(self, required_by: set[Distribution | str]) -> VersionConflict: ... + def with_context(self, required_by: set[str]) -> Self | ContextualVersionConflict: ... class ContextualVersionConflict(VersionConflict): + def __init__(self, dist: Distribution, req: Requirement, required_by: set[str], /, *args: object) -> None: ... @property - def required_by(self) -> set[Distribution | str]: ... + def required_by(self) -> set[str]: ... class UnknownExtra(ResolutionError): ... @@ -372,7 +378,7 @@ class Distribution(NullProvider): @classmethod def from_filename(cls, filename: str, metadata: _MetadataType = None, **kw: str | None | int) -> Distribution: ... def as_requirement(self) -> Requirement: ... - def load_entry_point(self, group: str, name: str) -> Any: ... + def load_entry_point(self, group: str, name: str) -> _ResolvedEntryPoint: ... @overload def get_entry_map(self, group: None = None) -> dict[str, dict[str, EntryPoint]]: ... @overload