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,6 +1,6 @@
import os
import types
from _typeshed import StrPath
from os import PathLike
from typing import IO, Any, List, Optional, Protocol, Tuple, TypeVar, Union
from _imp import (
@@ -57,7 +57,7 @@ def load_module(name: str, file: Optional[_FileLike], filename: str, details: Tu
# IO[Any] is a TextIOWrapper if name is a .py file, and a FileIO otherwise.
def find_module(
name: str, path: Union[None, List[str], List[os.PathLike[str]], List[StrPath]] = ...
name: str, path: Union[None, List[str], List[PathLike[str]], List[StrPath]] = ...
) -> Tuple[IO[Any], str, Tuple[str, str, int]]: ...
def reload(module: types.ModuleType) -> types.ModuleType: ...
def init_builtin(name: str) -> Optional[types.ModuleType]: ...

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]] = ...,

View File

@@ -1,9 +1,9 @@
import sys
from typing import IO, Dict, List, Optional, Sequence, Tuple, Union
from _typeshed import StrPath
from typing import IO, Dict, List, Optional, Sequence, Tuple
if sys.version_info >= (3, 8):
from os import PathLike
def guess_type(url: Union[str, PathLike[str]], strict: bool = ...) -> Tuple[Optional[str], Optional[str]]: ...
def guess_type(url: StrPath, strict: bool = ...) -> Tuple[Optional[str], Optional[str]]: ...
else:
def guess_type(url: str, strict: bool = ...) -> Tuple[Optional[str], Optional[str]]: ...

View File

@@ -7,6 +7,7 @@ from _typeshed import (
OpenBinaryModeUpdating,
OpenBinaryModeWriting,
OpenTextMode,
StrPath,
)
from builtins import OSError
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper
@@ -367,8 +368,8 @@ if sys.platform != "win32":
f_namemax: int
# ----- os function stubs -----
def fsencode(filename: Union[str, bytes, PathLike[Any]]) -> bytes: ...
def fsdecode(filename: Union[str, bytes, PathLike[Any]]) -> str: ...
def fsencode(filename: AnyPath) -> bytes: ...
def fsdecode(filename: AnyPath) -> str: ...
@overload
def fspath(path: str) -> str: ...
@overload
@@ -687,7 +688,7 @@ if sys.platform != "win32":
if sys.version_info >= (3, 7):
@overload
def fwalk(
top: Union[str, PathLike[str]] = ...,
top: StrPath = ...,
topdown: bool = ...,
onerror: Optional[_OnError] = ...,
*,
@@ -705,7 +706,7 @@ if sys.platform != "win32":
) -> Iterator[Tuple[bytes, List[bytes], List[bytes], int]]: ...
else:
def fwalk(
top: Union[str, PathLike[str]] = ...,
top: StrPath = ...,
topdown: bool = ...,
onerror: Optional[_OnError] = ...,
*,

View File

@@ -1,5 +1,5 @@
import os
import sys
from _typeshed import AnyPath
from datetime import date, datetime, time
from typing import Any, Callable, Generator, Iterable, Iterator, List, Optional, Protocol, Tuple, Type, TypeVar, Union
@@ -66,7 +66,7 @@ def complete_statement(sql: str) -> bool: ...
if sys.version_info >= (3, 7):
def connect(
database: Union[bytes, str, os.PathLike[str]],
database: AnyPath,
timeout: float = ...,
detect_types: int = ...,
isolation_level: Optional[str] = ...,

View File

@@ -1,6 +1,6 @@
import sys
from _typeshed import AnyPath
from builtins import open as _builtin_open
from os import PathLike
from token import * # noqa: F403
from typing import (
Any,
@@ -62,7 +62,7 @@ def untokenize(iterable: Iterable[_Token]) -> Any: ...
def detect_encoding(readline: Callable[[], bytes]) -> Tuple[str, Sequence[bytes]]: ...
def tokenize(readline: Callable[[], bytes]) -> Generator[TokenInfo, None, None]: ...
def generate_tokens(readline: Callable[[], str]) -> Generator[TokenInfo, None, None]: ... # undocumented
def open(filename: Union[str, bytes, int, PathLike[Any]]) -> TextIO: ...
def open(filename: Union[AnyPath, int]) -> TextIO: ...
def group(*choices: str) -> str: ... # undocumented
def any(*choices: str) -> str: ... # undocumented
def maybe(*choices: str) -> str: ... # undocumented

View File

@@ -1,6 +1,6 @@
import os
import ssl
import sys
from _typeshed import AnyPath
from email.message import Message
from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol
from http.cookiejar import CookieJar
@@ -271,7 +271,7 @@ class HTTPErrorProcessor(BaseHandler):
def urlretrieve(
url: str,
filename: Optional[Union[str, os.PathLike[Any]]] = ...,
filename: Optional[AnyPath] = ...,
reporthook: Optional[Callable[[int, int, int], None]] = ...,
data: Optional[bytes] = ...,
) -> Tuple[str, HTTPMessage]: ...

View File

@@ -1,7 +1,7 @@
import os
import typing
from _typeshed import StrPath
from datetime import tzinfo
from typing import Any, AnyStr, Iterable, Optional, Protocol, Sequence, Set, Type, Union
from typing import Any, Iterable, Optional, Protocol, Sequence, Set, Type
_T = typing.TypeVar("_T", bound="ZoneInfo")
@@ -23,7 +23,7 @@ class ZoneInfo(tzinfo):
# Note: Both here and in clear_cache, the types allow the use of `str` where
# a sequence of strings is required. This should be remedied if a solution
# to this typing bug is found: https://github.com/python/typing/issues/256
def reset_tzpath(to: Optional[Sequence[Union[os.PathLike[AnyStr], str]]] = ...) -> None: ...
def reset_tzpath(to: Optional[Sequence[StrPath]] = ...) -> None: ...
def available_timezones() -> Set[str]: ...
TZPATH: Sequence[str]