Skip to content

Commit

Permalink
Use strict pyright configs for pkg_resources (python#11538)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Mar 8, 2024
1 parent d424547 commit c35b3bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"stubs/redis",
"stubs/requests",
"stubs/requests-oauthlib",
"stubs/setuptools",
"stubs/setuptools/setuptools",
"stubs/stripe",
"stubs/tqdm",
"stubs/ttkthemes",
Expand Down
41 changes: 23 additions & 18 deletions stubs/setuptools/pkg_resources/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _ModuleLike: TypeAlias = object | types.ModuleType # Any object that optionally
_ProviderFactoryType: TypeAlias = Callable[[_ModuleLike], IResourceProvider]
_DistFinderType: TypeAlias = Callable[[_T, str, bool], Iterable[Distribution]]
_NSHandlerType: TypeAlias = Callable[[_T, str, str, types.ModuleType], str | None]
_ResourceStream: TypeAlias = Incomplete # A readable file-like object

__all__ = [
"require",
Expand Down Expand Up @@ -104,7 +105,7 @@ class _ZipLoaderModule(Protocol):
__loader__: zipimport.zipimporter

def declare_namespace(packageName: str) -> None: ...
def fixup_namespace_packages(path_item: str, parent=None) -> None: ...
def fixup_namespace_packages(path_item: str, parent: str | None = None) -> None: ...

class WorkingSet:
entries: list[str]
Expand All @@ -122,10 +123,14 @@ class WorkingSet:
env: Environment | None = None,
installer: _InstallerType | None = None,
replace_conflicting: bool = False,
extras=None,
extras: tuple[str, ...] | None = None,
) -> list[Distribution]: ...
def find_plugins(
self, plugin_env: Environment, full_env: Environment | None = None, installer=None, fallback: bool = True
self,
plugin_env: Environment,
full_env: Environment | None = None,
installer: _InstallerType | None = None,
fallback: bool = True,
) -> tuple[list[Distribution], dict[Distribution, Exception]]: ...
def require(self, *requirements: _NestedStr) -> Sequence[Distribution]: ...
def subscribe(self, callback: Callable[[Distribution], object], existing: bool = True) -> None: ...
Expand Down Expand Up @@ -304,15 +309,15 @@ def register_loader_type(loader_type: type[_ModuleLike], provider_factory: _Prov
def register_namespace_handler(importer_type: type[_T], namespace_handler: _NSHandlerType[_T]) -> None: ...

class IResourceProvider(IMetadataProvider, Protocol):
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): ...
def get_resource_filename(self, manager: ResourceManager, resource_name: str) -> StrPath: ...
def get_resource_stream(self, manager: ResourceManager, resource_name: str) -> _ResourceStream: ...
def get_resource_string(self, manager: ResourceManager, resource_name: str) -> bytes: ...
def has_resource(self, resource_name: str) -> bool: ...
def resource_isdir(self, resource_name: str) -> bool: ...
def resource_listdir(self, resource_name: str) -> list[str]: ...

def invalid_marker(text) -> SyntaxError | Literal[False]: ...
def evaluate_marker(text, extra: Incomplete | None = None): ...
def invalid_marker(text: str) -> SyntaxError | Literal[False]: ...
def evaluate_marker(text: str, extra: Incomplete | None = None) -> bool: ...

class NullProvider:
egg_name: str | None
Expand All @@ -321,16 +326,16 @@ class NullProvider:
module_path: str | None

def __init__(self, module: _ModuleLike) -> None: ...
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 get_resource_filename(self, manager: ResourceManager, resource_name: str) -> str: ...
def get_resource_stream(self, manager: ResourceManager, resource_name: str) -> BytesIO: ...
def get_resource_string(self, manager: ResourceManager, resource_name: str) -> bytes: ...
def has_resource(self, resource_name: str) -> bool: ...
def has_metadata(self, name: str) -> bool: ...
def get_metadata(self, name: str) -> str: ...
def get_metadata_lines(self, name: str) -> chain[str]: ...
def resource_isdir(self, resource_name) -> bool: ...
def resource_isdir(self, resource_name: str) -> bool: ...
def metadata_isdir(self, name: str) -> bool: ...
def resource_listdir(self, resource_name) -> list[str]: ...
def resource_listdir(self, resource_name: str) -> list[str]: ...
def metadata_listdir(self, name: str) -> list[str]: ...
def run_script(self, script_name: str, namespace: dict[str, Any]) -> None: ...

Expand Down Expand Up @@ -383,7 +388,7 @@ class Distribution(NullProvider):
@overload
def get_entry_map(self, group: str) -> dict[str, EntryPoint]: ...
def get_entry_info(self, group: str, name: str) -> EntryPoint | None: ...
def insert_on(self, path, loc: Incomplete | None = None, replace: bool = False) -> None: ...
def insert_on(self, path: list[str], 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 | IResourceProvider | None) -> Requirement: ...
Expand Down

0 comments on commit c35b3bc

Please sign in to comment.