Replace PathLike unions with aliases from _typeshed (#5467)

Standardize on 'from os import PathLike'
This commit is contained in:
Sebastian Rittau
2021-05-16 21:38:00 +02:00
committed by GitHub
parent d72b1e8149
commit e5abd08f93
9 changed files with 30 additions and 28 deletions

View File

@@ -1,11 +1,12 @@
import abc
import os
import pathlib
import sys
from _typeshed import StrPath
from email.message import Message
from importlib.abc import MetaPathFinder
from os import PathLike
from pathlib import Path
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, Union, overload
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, overload
if sys.version_info >= (3, 8):
class PackageNotFoundError(ModuleNotFoundError): ...
@@ -20,7 +21,7 @@ if sys.version_info >= (3, 8):
class PackagePath(pathlib.PurePosixPath):
def read_text(self, encoding: str = ...) -> str: ...
def read_binary(self) -> bytes: ...
def locate(self) -> os.PathLike[str]: ...
def locate(self) -> PathLike[str]: ...
# The following attributes are not defined on PackagePath, but are dynamically added by Distribution.files:
hash: Optional[FileHash]
size: Optional[int]
@@ -33,7 +34,7 @@ if sys.version_info >= (3, 8):
@abc.abstractmethod
def read_text(self, filename: str) -> Optional[str]: ...
@abc.abstractmethod
def locate_file(self, path: Union[os.PathLike[str], str]) -> os.PathLike[str]: ...
def locate_file(self, path: StrPath) -> PathLike[str]: ...
@classmethod
def from_name(cls, name: str) -> Distribution: ...
@overload
@@ -45,7 +46,7 @@ if sys.version_info >= (3, 8):
cls, *, context: None = ..., name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any
) -> Iterable[Distribution]: ...
@staticmethod
def at(path: Union[str, os.PathLike[str]]) -> PathDistribution: ...
def at(path: StrPath) -> PathDistribution: ...
@property
def metadata(self) -> Message: ...
@property
@@ -69,8 +70,8 @@ if sys.version_info >= (3, 8):
def find_distributions(cls, context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
class PathDistribution(Distribution):
def __init__(self, path: Path) -> None: ...
def read_text(self, filename: Union[str, os.PathLike[str]]) -> str: ...
def locate_file(self, path: Union[str, os.PathLike[str]]) -> os.PathLike[str]: ...
def read_text(self, filename: StrPath) -> str: ...
def locate_file(self, path: StrPath) -> PathLike[str]: ...
def distribution(distribution_name: str) -> Distribution: ...
@overload
def distributions(*, context: DistributionFinder.Context) -> Iterable[Distribution]: ...

View File

@@ -1,8 +1,8 @@
import importlib.abc
import importlib.machinery
import os
import types
from typing import Any, Callable, List, Optional, Union
from _typeshed import AnyPath
from typing import Any, Callable, List, Optional
def module_for_loader(fxn: Callable[..., types.ModuleType]) -> Callable[..., types.ModuleType]: ...
def set_loader(fxn: Callable[..., types.ModuleType]) -> Callable[..., types.ModuleType]: ...
@@ -20,7 +20,7 @@ def spec_from_loader(
) -> Optional[importlib.machinery.ModuleSpec]: ...
def spec_from_file_location(
name: str,
location: Optional[Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]] = ...,
location: Optional[AnyPath] = ...,
*,
loader: Optional[importlib.abc.Loader] = ...,
submodule_search_locations: Optional[List[str]] = ...,