Skip to content

Commit

Permalink
pkg_resources: Updates from upstream typing merge (#11455)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Mar 8, 2024
1 parent 3646f64 commit af84d2f
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions stubs/setuptools/pkg_resources/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -163,18 +164,19 @@ 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): ...

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: ...
Expand All @@ -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
Expand All @@ -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: ...
Expand Down Expand Up @@ -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): ...
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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]: ...
Expand All @@ -339,26 +338,26 @@ 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,
location: str | None = None,
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: ...
Expand All @@ -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
Expand All @@ -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]: ...

Expand Down Expand Up @@ -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: ...
Expand Down

0 comments on commit af84d2f

Please sign in to comment.