From 44f35bf303b075617ccc68c96c0cc4fa9c4569ac Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 28 Feb 2024 20:35:06 -0500 Subject: [PATCH] `pkg_resources`: don't ignore "missing symbol from stub" in stubtest --- .../setuptools/@tests/stubtest_allowlist.txt | 5 ---- stubs/setuptools/pkg_resources/__init__.pyi | 28 +++++++++++-------- .../pkg_resources/extern/__init__.pyi | 17 +++++++++++ 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 stubs/setuptools/pkg_resources/extern/__init__.pyi diff --git a/stubs/setuptools/@tests/stubtest_allowlist.txt b/stubs/setuptools/@tests/stubtest_allowlist.txt index 9edb8ef70a0b..57ecb67e4319 100644 --- a/stubs/setuptools/@tests/stubtest_allowlist.txt +++ b/stubs/setuptools/@tests/stubtest_allowlist.txt @@ -44,8 +44,3 @@ setuptools._distutils.* # Other vendored code setuptools._vendor.* pkg_resources._vendor.* -# Deprecated in favor of importlib.resources, importlib.metadata and their backports -# So like distutils, we only add what we need to reference. -pkg_resources.AvailableDistributions -pkg_resources.ResourceManager -pkg_resources.extern diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index d15e1c9a7357..25be472df0c0 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -6,7 +6,7 @@ from abc import ABCMeta from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from io import BytesIO from re import Pattern -from typing import IO, Any, ClassVar, Literal, Protocol, TypeVar, overload, type_check_only +from typing import IO, Any, ClassVar, Literal, Protocol, TypeVar, overload from typing_extensions import Self, TypeAlias from ._vendored_packaging import requirements as packaging_requirements, version as packaging_version @@ -80,6 +80,8 @@ class Environment: def __iadd__(self, other: Distribution | Environment) -> Self: ... def __add__(self, other: Distribution | Environment) -> Environment: ... +AvailableDistributions = Environment + def parse_requirements(strs: str | Iterable[str]) -> Generator[Requirement, None, None]: ... class RequirementParseError(packaging_requirements.InvalidRequirement): ... @@ -142,8 +144,10 @@ SOURCE_DIST: int CHECKOUT_DIST: int DEVELOP_DIST: int -@type_check_only -class _IResourceManager(Protocol): +class ResourceManager: + extraction_path: Incomplete + 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: ... @@ -151,10 +155,10 @@ class _IResourceManager(Protocol): def resource_string(self, package_or_requirement: _PkgReqType, resource_name: str) -> bytes: ... def resource_listdir(self, package_or_requirement: _PkgReqType, resource_name: str) -> list[str]: ... def extraction_error(self) -> None: ... - def get_cache_path(self, archive_name: str, names: Iterable[str] = ...) -> str: ... + def get_cache_path(self, archive_name: str, names: Iterable[str] = ()) -> str: ... def postprocess(self, tempname: str, filename: str) -> None: ... def set_extraction_path(self, path: str) -> None: ... - def cleanup_resources(self, force: bool = ...) -> list[str]: ... + def cleanup_resources(self, force: bool = False) -> list[str]: ... def resource_exists(package_or_requirement: _PkgReqType, resource_name: str) -> bool: ... def resource_isdir(package_or_requirement: _PkgReqType, resource_name: str) -> bool: ... @@ -203,7 +207,7 @@ class ContextualVersionConflict(VersionConflict): class UnknownExtra(ResolutionError): ... class ExtractionError(Exception): - manager: _IResourceManager + manager: ResourceManager cache_path: str original_error: Exception @@ -214,9 +218,9 @@ def register_loader_type(loader_type: type, provider_factory: Callable[[types.Mo def register_namespace_handler(importer_type: type, namespace_handler: _NSHandlerType) -> None: ... class IResourceProvider(IMetadataProvider, Protocol): - def get_resource_filename(self, manager: _IResourceManager, resource_name): ... - def get_resource_stream(self, manager: _IResourceManager, resource_name): ... - def get_resource_string(self, manager: _IResourceManager, resource_name): ... + def get_resource_filename(self, manager: ResourceManager, resource_name): ... + def get_resource_stream(self, manager: ResourceManager, resource_name): ... + def get_resource_string(self, manager: ResourceManager, resource_name): ... def has_resource(self, resource_name): ... def resource_isdir(self, resource_name): ... def resource_listdir(self, resource_name): ... @@ -231,9 +235,9 @@ class NullProvider: module_path: str | None def __init__(self, module) -> None: ... - def get_resource_filename(self, manager: _IResourceManager, resource_name) -> str: ... - def get_resource_stream(self, manager: _IResourceManager, resource_name) -> BytesIO: ... - def get_resource_string(self, manager: _IResourceManager, resource_name): ... + def get_resource_filename(self, manager: ResourceManager, resource_name) -> str: ... + 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 get_metadata(self, name: str) -> str: ... diff --git a/stubs/setuptools/pkg_resources/extern/__init__.pyi b/stubs/setuptools/pkg_resources/extern/__init__.pyi new file mode 100644 index 000000000000..663a01e91a1d --- /dev/null +++ b/stubs/setuptools/pkg_resources/extern/__init__.pyi @@ -0,0 +1,17 @@ +from _typeshed import Incomplete +from collections.abc import Generator + +class VendorImporter: + root_name: Incomplete + vendored_names: Incomplete + vendor_pkg: Incomplete + def __init__(self, root_name, vendored_names=(), vendor_pkg: Incomplete | None = None) -> None: ... + @property + def search_path(self) -> Generator[Incomplete, None, None]: ... + def load_module(self, fullname): ... + def create_module(self, spec): ... + def exec_module(self, module) -> None: ... + def find_spec(self, fullname, path: Incomplete | None = None, target: Incomplete | None = None): ... + def install(self) -> None: ... + +names: Incomplete