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

Update setuptools to v70.1.1 #12215

Merged
merged 3 commits into from
Jun 26, 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
55 changes: 31 additions & 24 deletions stubs/setuptools/pkg_resources/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,33 @@ from io import BytesIO
from itertools import chain
from pkgutil import get_importer as get_importer
from re import Pattern
from typing import IO, Any, ClassVar, Final, Literal, NamedTuple, NoReturn, Protocol, TypeVar, overload, type_check_only
from typing import IO, Any, ClassVar, Final, Literal, NamedTuple, NoReturn, Protocol, TypeVar, overload
from typing_extensions import Self, TypeAlias
from zipfile import ZipInfo

from ._vendored_packaging import requirements as packaging_requirements, version as packaging_version

# defined in setuptools
_T = TypeVar("_T")
_DistributionT = TypeVar("_DistributionT", bound=Distribution)
_NestedStr: TypeAlias = str | Iterable[_NestedStr]
_InstallerTypeT: TypeAlias = Callable[[Requirement], _DistributionT] # noqa: Y043
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This has been raised upstream: pypa/setuptools#4436

_InstallerType: TypeAlias = Callable[[Requirement], Distribution | None]
_PkgReqType: TypeAlias = str | Requirement
_EPDistType: TypeAlias = Distribution | _PkgReqType
_MetadataType: TypeAlias = IResourceProvider | None
_ResolvedEntryPoint: TypeAlias = Any # Can be any attribute in the module
_ResourceStream: TypeAlias = Incomplete # A readable file-like object
_ModuleLike: TypeAlias = object | types.ModuleType # Any object that optionally has __loader__ or __file__, usually a module
_ProviderFactoryType: TypeAlias = Callable[[_ModuleLike], IResourceProvider]
# Any: Should be _ModuleLike but we end up with issues where _ModuleLike doesn't have _ZipLoaderModule's __loader__
_ProviderFactoryType: TypeAlias = Callable[[Any], IResourceProvider]
_DistFinderType: TypeAlias = Callable[[_T, str, bool], Iterable[Distribution]]
_NSHandlerType: TypeAlias = Callable[[_T, str, str, types.ModuleType], str | None]
_ResourceStream: TypeAlias = Incomplete # A readable file-like object

# TODO: Use _typeshed.importlib.LoaderProtocol after mypy 1.11 is released
class _LoaderProtocol(Protocol):
def load_module(self, fullname: str, /) -> types.ModuleType: ...

# typeshed only
_D = TypeVar("_D", bound=Distribution)
_StrictInstallerType: TypeAlias = Callable[[Requirement], _D]

__all__ = [
"require",
"run_script",
Expand Down Expand Up @@ -108,7 +107,6 @@ __all__ = [
"AvailableDistributions",
]

@type_check_only
class _ZipLoaderModule(Protocol):
__loader__: zipimport.zipimporter

Expand All @@ -130,22 +128,22 @@ class WorkingSet:
self,
requirements: Iterable[Requirement],
env: Environment | None,
installer: _StrictInstallerType[_D],
installer: _InstallerTypeT[_DistributionT],
replace_conflicting: bool = False,
extras: tuple[str, ...] | None = None,
) -> list[_D]: ...
) -> list[_DistributionT]: ...
@overload
def resolve( # type: ignore[overload-overlap]
self,
requirements: Iterable[Requirement],
env: Environment | None = None,
*,
installer: _StrictInstallerType[_D],
installer: _InstallerTypeT[_DistributionT],
replace_conflicting: bool = False,
extras: tuple[str, ...] | None = None,
) -> list[_D]: ...
) -> list[_DistributionT]: ...
@overload
def resolve(
def resolve( # type: ignore[overload-overlap]
self,
requirements: Iterable[Requirement],
env: Environment | None = None,
Expand All @@ -155,17 +153,21 @@ class WorkingSet:
) -> list[Distribution]: ...
@overload
def find_plugins( # type: ignore[overload-overlap]
self, plugin_env: Environment, full_env: Environment | None, installer: _StrictInstallerType[_D], fallback: bool = True
) -> tuple[list[_D], dict[Distribution, Exception]]: ...
self,
plugin_env: Environment,
full_env: Environment | None,
installer: _InstallerTypeT[_DistributionT],
fallback: bool = True,
) -> tuple[list[_DistributionT], dict[Distribution, Exception]]: ...
@overload
def find_plugins( # type: ignore[overload-overlap]
self,
plugin_env: Environment,
full_env: Environment | None = None,
*,
installer: _StrictInstallerType[_D],
installer: _InstallerTypeT[_DistributionT],
fallback: bool = True,
) -> tuple[list[_D], dict[Distribution, Exception]]: ...
) -> tuple[list[_DistributionT], dict[Distribution, Exception]]: ...
@overload
def find_plugins(
self,
Expand All @@ -188,8 +190,12 @@ class Environment:
def add(self, dist: Distribution) -> None: ...
@overload
def best_match(
self, req: Requirement, working_set: WorkingSet, installer: _StrictInstallerType[_D], replace_conflicting: bool = False
) -> _D: ...
self,
req: Requirement,
working_set: WorkingSet,
installer: _InstallerTypeT[_DistributionT],
replace_conflicting: bool = False,
) -> _DistributionT: ...
@overload
def best_match(
self,
Expand All @@ -199,7 +205,7 @@ class Environment:
replace_conflicting: bool = False,
) -> Distribution | None: ...
@overload
def obtain(self, requirement: Requirement, installer: _StrictInstallerType[_D]) -> _D: ... # type: ignore[overload-overlap]
def obtain(self, requirement: Requirement, installer: _InstallerTypeT[_DistributionT]) -> _DistributionT: ... # type: ignore[overload-overlap]
@overload
def obtain(self, requirement: Requirement, installer: Callable[[Requirement], None] | None = None) -> None: ...
@overload
Expand Down Expand Up @@ -248,7 +254,7 @@ class EntryPoint:
self, require: Literal[True] = True, env: Environment | None = None, installer: _InstallerType | None = None
) -> _ResolvedEntryPoint: ...
@overload
def load(self, require: Literal[False], *args: Unused, **kwargs: Unused) -> _ResolvedEntryPoint: ...
def load(self, require: Literal[False], *args: Any, **kwargs: Any) -> _ResolvedEntryPoint: ...
def resolve(self) -> _ResolvedEntryPoint: ...
def require(self, env: Environment | None = None, installer: _InstallerType | None = None) -> None: ...
pattern: ClassVar[Pattern[str]]
Expand All @@ -272,7 +278,7 @@ class NoDists:
def __call__(self, fullpath: Unused) -> Iterator[Distribution]: ...

@overload
def get_distribution(dist: _D) -> _D: ...
def get_distribution(dist: _DistributionT) -> _DistributionT: ...
@overload
def get_distribution(dist: _PkgReqType) -> Distribution: ...

Expand Down Expand Up @@ -364,7 +370,7 @@ class NullProvider:
egg_name: str | None
egg_info: str | None
loader: _LoaderProtocol | None
module_path: str | None
module_path: str

def __init__(self, module: _ModuleLike) -> None: ...
def get_resource_filename(self, manager: ResourceManager, resource_name: str) -> str: ...
Expand Down Expand Up @@ -465,7 +471,8 @@ class EggMetadata(ZipProvider):
def __init__(self, importer: zipimport.zipimporter) -> None: ...

class EmptyProvider(NullProvider):
module_path: None
# A special case, we don't want all Providers inheriting from NullProvider to have a potentially None module_path
module_path: str | None # type:ignore[assignment]
def __init__(self) -> None: ...

empty_provider: EmptyProvider
Expand Down