Skip to content

Commit 52daae5

Browse files
authored
pkg_resources: Remove stray Anys and use more Self & NoReturn types (#11528)
1 parent 67176a4 commit 52daae5

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

stubs/setuptools/pkg_resources/__init__.pyi

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
55
from io import BytesIO
66
from pkgutil import get_importer as get_importer
77
from re import Pattern
8-
from typing import IO, Any, ClassVar, Final, Literal, Protocol, TypeVar, overload, type_check_only
8+
from typing import IO, Any, ClassVar, Final, Literal, NoReturn, Protocol, TypeVar, overload, type_check_only
99
from typing_extensions import Self, TypeAlias
1010
from zipfile import ZipInfo
1111

1212
from ._vendored_packaging import requirements as packaging_requirements, version as packaging_version
1313

1414
_T = TypeVar("_T")
1515
_D = TypeVar("_D", bound=Distribution)
16-
_NestedStr: TypeAlias = str | Iterable[str | Iterable[Any]]
16+
_NestedStr: TypeAlias = str | Iterable[str | Iterable[_NestedStr]]
1717
_InstallerType: TypeAlias = Callable[[Requirement], Distribution | None]
1818
_EPDistType: TypeAlias = Distribution | Requirement | str
1919
_MetadataType: TypeAlias = IResourceProvider | None
2020
_PkgReqType: TypeAlias = str | Requirement
21+
_ResolvedEntryPoint: TypeAlias = Any # Can be any attribute in the module
2122
_ModuleLike: TypeAlias = object | types.ModuleType # Any object that optionally has __loader__ or __file__, usually a module
2223
_ProviderFactoryType: TypeAlias = Callable[[_ModuleLike], IResourceProvider]
2324
_DistFinderType: TypeAlias = Callable[[_T, str, bool], Iterable[Distribution]]
@@ -158,7 +159,7 @@ class Environment:
158159
def obtain(self, requirement: Requirement, installer: Callable[[Requirement], _T]) -> _T: ...
159160
def __iter__(self) -> Iterator[str]: ...
160161
def __iadd__(self, other: Distribution | Environment) -> Self: ...
161-
def __add__(self, other: Distribution | Environment) -> Environment: ...
162+
def __add__(self, other: Distribution | Environment) -> Self: ...
162163

163164
AvailableDistributions = Environment
164165

@@ -178,7 +179,7 @@ class Requirement(packaging_requirements.Requirement):
178179
@staticmethod
179180
def parse(s: str | Iterable[str]) -> Requirement: ...
180181

181-
def load_entry_point(dist: _EPDistType, group: str, name: str) -> Any: ...
182+
def load_entry_point(dist: _EPDistType, group: str, name: str) -> _ResolvedEntryPoint: ...
182183
@overload
183184
def get_entry_map(dist: _EPDistType, group: None = None) -> dict[str, dict[str, EntryPoint]]: ...
184185
@overload
@@ -200,11 +201,13 @@ class EntryPoint:
200201
extras: tuple[str, ...] = (),
201202
dist: Distribution | None = None,
202203
) -> None: ...
203-
def load(self, require: bool = True, env: Environment | None = ..., installer: _InstallerType | None = ...) -> Any: ...
204-
def resolve(self) -> Any: ...
204+
def load(
205+
self, require: bool = True, env: Environment | None = ..., installer: _InstallerType | None = ...
206+
) -> _ResolvedEntryPoint: ...
207+
def resolve(self) -> _ResolvedEntryPoint: ...
205208
def require(self, env: Environment | None = None, installer: _InstallerType | None = None) -> None: ...
206209
@classmethod
207-
def parse(cls, src: str, dist: Distribution | None = None) -> EntryPoint: ...
210+
def parse(cls, src: str, dist: Distribution | None = None) -> Self: ...
208211
@classmethod
209212
def parse_group(cls, group: str, lines: str | Sequence[str], dist: Distribution | None = None) -> dict[str, EntryPoint]: ...
210213
@classmethod
@@ -235,7 +238,7 @@ class ResourceManager:
235238
def resource_stream(self, package_or_requirement: _PkgReqType, resource_name: str) -> IO[bytes]: ...
236239
def resource_string(self, package_or_requirement: _PkgReqType, resource_name: str) -> bytes: ...
237240
def resource_listdir(self, package_or_requirement: _PkgReqType, resource_name: str) -> list[str]: ...
238-
def extraction_error(self) -> None: ...
241+
def extraction_error(self) -> NoReturn: ...
239242
def get_cache_path(self, archive_name: str, names: Iterable[str] = ()) -> str: ...
240243
def postprocess(self, tempname: str, filename: str) -> None: ...
241244
def set_extraction_path(self, path: str) -> None: ...
@@ -267,25 +270,28 @@ class IMetadataProvider(Protocol):
267270
class ResolutionError(Exception): ...
268271

269272
class DistributionNotFound(ResolutionError):
273+
def __init__(self, req: Requirement, requirers: set[str] | None, /, *args: object) -> None: ...
270274
@property
271275
def req(self) -> Requirement: ...
272276
@property
273-
def requirers(self) -> set[str]: ...
277+
def requirers(self) -> set[str] | None: ...
274278
@property
275279
def requirers_str(self) -> str: ...
276280
def report(self) -> str: ...
277281

278282
class VersionConflict(ResolutionError):
283+
def __init__(self, dist: Distribution, req: Requirement, /, *args: object) -> None: ...
279284
@property
280-
def dist(self) -> Any: ...
285+
def dist(self) -> Distribution: ...
281286
@property
282-
def req(self) -> Any: ...
287+
def req(self) -> Requirement: ...
283288
def report(self) -> str: ...
284-
def with_context(self, required_by: set[Distribution | str]) -> VersionConflict: ...
289+
def with_context(self, required_by: set[str]) -> Self | ContextualVersionConflict: ...
285290

286291
class ContextualVersionConflict(VersionConflict):
292+
def __init__(self, dist: Distribution, req: Requirement, required_by: set[str], /, *args: object) -> None: ...
287293
@property
288-
def required_by(self) -> set[Distribution | str]: ...
294+
def required_by(self) -> set[str]: ...
289295

290296
class UnknownExtra(ResolutionError): ...
291297

@@ -372,7 +378,7 @@ class Distribution(NullProvider):
372378
@classmethod
373379
def from_filename(cls, filename: str, metadata: _MetadataType = None, **kw: str | None | int) -> Distribution: ...
374380
def as_requirement(self) -> Requirement: ...
375-
def load_entry_point(self, group: str, name: str) -> Any: ...
381+
def load_entry_point(self, group: str, name: str) -> _ResolvedEntryPoint: ...
376382
@overload
377383
def get_entry_map(self, group: None = None) -> dict[str, dict[str, EntryPoint]]: ...
378384
@overload

0 commit comments

Comments
 (0)