From af84d2fbfe8640c9f5049bfd0e74ea3270c8ea2c Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 8 Mar 2024 09:23:55 -0500 Subject: [PATCH] `pkg_resources`: Updates from upstream typing merge (#11455) --- stubs/setuptools/pkg_resources/__init__.pyi | 72 ++++++++++----------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index a8614a67dcb7..c67416fc99a2 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -1,8 +1,9 @@ import types import zipimport -from _typeshed import Incomplete +from _typeshed import Incomplete, StrPath, Unused from collections.abc import Callable, Generator, Iterable, Iterator, Sequence 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, NoReturn, Protocol, TypeVar, overload, type_check_only @@ -13,11 +14,11 @@ from ._vendored_packaging import requirements as packaging_requirements, version _T = TypeVar("_T") _D = TypeVar("_D", bound=Distribution) -_NestedStr: TypeAlias = str | Iterable[str | Iterable[_NestedStr]] +_NestedStr: TypeAlias = str | Iterable[_NestedStr] _InstallerType: TypeAlias = Callable[[Requirement], Distribution | None] -_EPDistType: TypeAlias = Distribution | Requirement | str -_MetadataType: TypeAlias = IResourceProvider | None _PkgReqType: TypeAlias = str | Requirement +_EPDistType: TypeAlias = Distribution | _PkgReqType +_MetadataType: TypeAlias = IResourceProvider | None _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] @@ -163,7 +164,7 @@ class Environment: AvailableDistributions = Environment -def parse_requirements(strs: str | Iterable[str]) -> Generator[Requirement, None, None]: ... +def parse_requirements(strs: _NestedStr) -> Iterator[Requirement]: ... class RequirementParseError(packaging_requirements.InvalidRequirement): ... @@ -171,10 +172,11 @@ class Requirement(packaging_requirements.Requirement): unsafe_name: str project_name: str key: str - extras: tuple[str, ...] # type: ignore[assignment] # incompatible override of attribute on base class + # packaging.requirements.Requirement uses a set for its extras. setuptools/pkg_resources uses a variable-length tuple + extras: tuple[str, ...] # type: ignore[assignment] specs: list[tuple[str, str]] def __init__(self, requirement_string: str) -> None: ... - def __eq__(self, other_requirement: object) -> bool: ... + def __eq__(self, other: object) -> bool: ... def __contains__(self, item: Distribution | str | tuple[str, ...]) -> bool: ... @staticmethod def parse(s: str | Iterable[str]) -> Requirement: ... @@ -187,33 +189,31 @@ def get_entry_map(dist: _EPDistType, group: str) -> dict[str, EntryPoint]: ... def get_entry_info(dist: _EPDistType, group: str, name: str) -> EntryPoint | None: ... class EntryPoint: - pattern: ClassVar[Pattern[str]] name: str module_name: str attrs: tuple[str, ...] extras: tuple[str, ...] dist: Distribution | None def __init__( - self, - name: str, - module_name: str, - attrs: tuple[str, ...] = (), - extras: tuple[str, ...] = (), - dist: Distribution | None = None, + self, name: str, module_name: str, attrs: Iterable[str] = (), extras: Iterable[str] = (), dist: Distribution | None = None ) -> None: ... + @overload def load( - self, require: bool = True, env: Environment | None = ..., installer: _InstallerType | None = ... + 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 resolve(self) -> _ResolvedEntryPoint: ... def require(self, env: Environment | None = None, installer: _InstallerType | None = None) -> None: ... + pattern: ClassVar[Pattern[str]] @classmethod 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]: ... + def parse_group(cls, group: str, lines: _NestedStr, dist: Distribution | None = None) -> dict[str, Self]: ... @classmethod def parse_map( - cls, data: dict[str, str | Sequence[str]] | str | Sequence[str], dist: Distribution | None = None - ) -> dict[str, EntryPoint]: ... + cls, data: str | Iterable[str] | dict[str, str | Iterable[str]], dist: Distribution | None = None + ) -> dict[str, dict[str, Self]]: ... def find_distributions(path_item: str, only: bool = False) -> Generator[Distribution, None, None]: ... @overload @@ -229,9 +229,8 @@ CHECKOUT_DIST: Final = 0 DEVELOP_DIST: Final = -1 class ResourceManager: - extraction_path: Incomplete + extraction_path: str | None cached_files: Incomplete - def __init__(self) -> None: ... def resource_exists(self, package_or_requirement: _PkgReqType, resource_name: str) -> bool: ... def resource_isdir(self, package_or_requirement: _PkgReqType, resource_name: str) -> bool: ... def resource_filename(self, package_or_requirement: _PkgReqType, resource_name: str) -> str: ... @@ -260,11 +259,11 @@ def get_provider(moduleOrReq: str) -> IResourceProvider: ... def get_provider(moduleOrReq: Requirement) -> Distribution: ... class IMetadataProvider(Protocol): - def has_metadata(self, name: str) -> bool | None: ... + def has_metadata(self, name: str) -> bool: ... + def get_metadata(self, name: str) -> str: ... + def get_metadata_lines(self, name: str) -> Iterator[str]: ... def metadata_isdir(self, name: str) -> bool: ... def metadata_listdir(self, name: str) -> list[str]: ... - def get_metadata(self, name: str) -> str: ... - def get_metadata_lines(self, name: str) -> Generator[str, None, None]: ... def run_script(self, script_name: str, namespace: dict[str, Any]) -> None: ... class ResolutionError(Exception): ... @@ -298,7 +297,7 @@ class UnknownExtra(ResolutionError): ... class ExtractionError(Exception): manager: ResourceManager cache_path: str - original_error: Exception + original_error: BaseException | 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: ... @@ -326,9 +325,9 @@ class NullProvider: def get_resource_stream(self, manager: ResourceManager, resource_name) -> BytesIO: ... def get_resource_string(self, manager: ResourceManager, resource_name): ... def has_resource(self, resource_name) -> bool: ... - def has_metadata(self, name: str) -> bool | None: ... + def has_metadata(self, name: str) -> bool: ... def get_metadata(self, name: str) -> str: ... - def get_metadata_lines(self, name: str) -> Generator[str, None, None]: ... + def get_metadata_lines(self, name: str) -> chain[str]: ... def resource_isdir(self, resource_name) -> bool: ... def metadata_isdir(self, name: str) -> bool: ... def resource_listdir(self, resource_name) -> list[str]: ... @@ -339,9 +338,9 @@ class NullProvider: class Distribution(NullProvider): PKG_INFO: ClassVar[str] project_name: str - py_version: str + py_version: str | None platform: str | None - location: str + location: str | None precedence: int def __init__( self, @@ -349,16 +348,16 @@ class Distribution(NullProvider): metadata: _MetadataType = None, project_name: str | None = None, version: str | None = None, - py_version: str = ..., + py_version: str | None = ..., platform: str | None = None, precedence: int = 3, ) -> None: ... @classmethod def from_location( - cls, location: str, basename: str, metadata: _MetadataType = None, **kw: str | None | int + cls, location: str, basename: str, metadata: _MetadataType = None, *, precedence: int = 3 ) -> Distribution: ... @property - def hashcmp(self) -> tuple[Incomplete, int, str, Incomplete | None, str, str]: ... + def hashcmp(self) -> tuple[parse_version, int, str, str | None, str, str]: ... def __hash__(self) -> int: ... def __lt__(self, other: Distribution) -> bool: ... def __le__(self, other: Distribution) -> bool: ... @@ -372,11 +371,11 @@ class Distribution(NullProvider): def parsed_version(self) -> packaging_version.Version: ... @property def version(self) -> str: ... - def requires(self, extras: tuple[str, ...] = ()) -> list[Requirement]: ... + def requires(self, extras: Iterable[str] = ()) -> list[Requirement]: ... def activate(self, path: list[str] | None = None, replace: bool = False) -> None: ... def egg_name(self) -> str: ... # type: ignore[override] # supertype's egg_name is a variable, not a method @classmethod - def from_filename(cls, filename: str, metadata: _MetadataType = None, **kw: str | None | int) -> Distribution: ... + def from_filename(cls, filename: str, metadata: _MetadataType = None, *, precedence: int = 3) -> Distribution: ... def as_requirement(self) -> Requirement: ... def load_entry_point(self, group: str, name: str) -> _ResolvedEntryPoint: ... @overload @@ -387,7 +386,7 @@ class Distribution(NullProvider): def insert_on(self, path, loc: Incomplete | None = None, replace: bool = False) -> None: ... def check_version_conflict(self) -> None: ... def has_version(self) -> bool: ... - def clone(self, **kw: str | int | None) -> Requirement: ... + def clone(self, **kw: str | int | IResourceProvider | None) -> Requirement: ... @property def extras(self) -> list[str]: ... @@ -426,13 +425,14 @@ class EmptyProvider(NullProvider): empty_provider: EmptyProvider class FileMetadata(EmptyProvider): - def __init__(self, path: str) -> None: ... + path: StrPath + def __init__(self, path: StrPath) -> None: ... class PEP440Warning(RuntimeWarning): ... parse_version = packaging_version.Version -def yield_lines(iterable: _NestedStr) -> Generator[str, None, None]: ... +def yield_lines(iterable: _NestedStr) -> chain[str]: ... def split_sections(s: _NestedStr) -> Generator[tuple[str | None, list[str]], None, None]: ... def safe_name(name: str) -> str: ... def safe_version(version: str) -> str: ...