-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
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 7df4da3
Complete and strict typing for pkg_resources
Avasam e35218b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 24a8983
More fixes from merging return types
Avasam 230da10
Merge branch 'strict-setuptools.pkg_resources' of https://github.com/…
Avasam 360c2e1
.
Avasam 2fa848f
load and resolve, used directly, can actually be anything
Avasam 2927d66
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam add0fec
Solve pytype issue
Avasam a5c6f83
Completely abstract away map as a return type
Avasam c358e29
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam bf98b15
Don't add new undocumented names
Avasam dfd3df5
Keep zipimport the same
Avasam 989e444
Remove unused aliases
Avasam 6ec1173
Override `pkg_resources.ZipProvider.loader` type
Avasam 8ceebe6
Merge branch 'pkg_resources.ZipProvider.loader' of https://github.com…
Avasam 990ba25
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam 03a9bc5
Add setuptools reference in comments
Avasam 25fc709
https://github.com/pypa/setuptools/pull/4254 merged upstream
Avasam 56bbac5
Merge branch 'strict-setuptools.pkg_resources' of https://github.com/…
Avasam 3c5ba1b
Improvements from pkg_resources merging upstream
Avasam b7e4a1b
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam 094a097
Merge branch 'main' of https://github.com/python/typeshed into strict…
Avasam dbc2b9d
Revert "Make `pkg_resources` pyright strict"
Avasam f97b36e
More polish
Avasam 71ea49f
Update stubs/setuptools/pkg_resources/__init__.pyi
Avasam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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,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: ... | ||
|
@@ -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: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]: ... | ||
|
@@ -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: ... | ||
|
@@ -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: ... | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pypa/setuptools#4254