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

pkg_resources: Updates from upstream typing merge #11455

Merged
merged 26 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e78f4c4
Reorder names to be closer to implementation
Avasam Feb 19, 2024
7df4da3
Complete and strict typing for pkg_resources
Avasam Feb 20, 2024
e35218b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2024
24a8983
More fixes from merging return types
Avasam Feb 20, 2024
230da10
Merge branch 'strict-setuptools.pkg_resources' of https://github.com/…
Avasam Feb 20, 2024
360c2e1
.
Avasam Feb 20, 2024
2fa848f
load and resolve, used directly, can actually be anything
Avasam Feb 21, 2024
2927d66
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam Feb 28, 2024
add0fec
Solve pytype issue
Avasam Feb 28, 2024
a5c6f83
Completely abstract away map as a return type
Avasam Feb 29, 2024
c358e29
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam Feb 29, 2024
bf98b15
Don't add new undocumented names
Avasam Feb 29, 2024
dfd3df5
Keep zipimport the same
Avasam Feb 29, 2024
989e444
Remove unused aliases
Avasam Feb 29, 2024
6ec1173
Override `pkg_resources.ZipProvider.loader` type
Avasam Feb 29, 2024
8ceebe6
Merge branch 'pkg_resources.ZipProvider.loader' of https://github.com…
Avasam Feb 29, 2024
990ba25
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam Mar 2, 2024
03a9bc5
Add setuptools reference in comments
Avasam Mar 4, 2024
25fc709
https://github.com/pypa/setuptools/pull/4254 merged upstream
Avasam Mar 5, 2024
56bbac5
Merge branch 'strict-setuptools.pkg_resources' of https://github.com/…
Avasam Mar 5, 2024
3c5ba1b
Improvements from pkg_resources merging upstream
Avasam Mar 6, 2024
b7e4a1b
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam Mar 6, 2024
094a097
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam Mar 8, 2024
dbc2b9d
Revert "Make `pkg_resources` pyright strict"
Avasam Mar 8, 2024
f97b36e
More polish
Avasam Mar 8, 2024
71ea49f
Update stubs/setuptools/pkg_resources/__init__.pyi
Avasam Mar 8, 2024
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
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: ...
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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: ...
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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
Loading