AnyStr cleanup (#5487)

* Replace all uses of StrPath, BytesPath, and AnyPath in Python 2 stubs.
* Add StrOrBytesPath as preferred alias for AnyPath.
* Replace all remaining AnyPath instances with StrOrBytesPath.
* Mark AnyPath as obsolete.

Part of #5470
This commit is contained in:
Sebastian Rittau
2021-05-17 20:45:48 +02:00
committed by GitHub
parent 51b7248154
commit f0bf6eebbd
67 changed files with 546 additions and 529 deletions

View File

@@ -1,6 +1,6 @@
import io
import sys
from _typeshed import AnyPath, StrPath
from _typeshed import StrOrBytesPath, StrPath
from types import TracebackType
from typing import IO, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Set, Tuple, Type, Union
@@ -50,7 +50,7 @@ PAX_NAME_FIELDS: Set[str]
ENCODING: str
def open(
name: Optional[AnyPath] = ...,
name: Optional[StrOrBytesPath] = ...,
mode: str = ...,
fileobj: Optional[IO[bytes]] = ...,
bufsize: int = ...,
@@ -72,7 +72,7 @@ class ExFileObject(io.BufferedReader):
class TarFile(Iterable[TarInfo]):
OPEN_METH: Mapping[str, str]
name: Optional[AnyPath]
name: Optional[StrOrBytesPath]
mode: str
fileobj: Optional[IO[bytes]]
format: Optional[int]
@@ -88,7 +88,7 @@ class TarFile(Iterable[TarInfo]):
offset: int # undocumented
def __init__(
self,
name: Optional[AnyPath] = ...,
name: Optional[StrOrBytesPath] = ...,
mode: str = ...,
fileobj: Optional[IO[bytes]] = ...,
format: Optional[int] = ...,
@@ -110,7 +110,7 @@ class TarFile(Iterable[TarInfo]):
@classmethod
def open(
cls,
name: Optional[AnyPath] = ...,
name: Optional[StrOrBytesPath] = ...,
mode: str = ...,
fileobj: Optional[IO[bytes]] = ...,
bufsize: int = ...,
@@ -128,7 +128,7 @@ class TarFile(Iterable[TarInfo]):
@classmethod
def taropen(
cls,
name: Optional[AnyPath],
name: Optional[StrOrBytesPath],
mode: str = ...,
fileobj: Optional[IO[bytes]] = ...,
*,
@@ -145,7 +145,7 @@ class TarFile(Iterable[TarInfo]):
@classmethod
def gzopen(
cls,
name: Optional[AnyPath],
name: Optional[StrOrBytesPath],
mode: str = ...,
fileobj: Optional[IO[bytes]] = ...,
compresslevel: int = ...,
@@ -162,7 +162,7 @@ class TarFile(Iterable[TarInfo]):
@classmethod
def bz2open(
cls,
name: Optional[AnyPath],
name: Optional[StrOrBytesPath],
mode: str = ...,
fileobj: Optional[IO[bytes]] = ...,
compresslevel: int = ...,
@@ -179,7 +179,7 @@ class TarFile(Iterable[TarInfo]):
@classmethod
def xzopen(
cls,
name: Optional[AnyPath],
name: Optional[StrOrBytesPath],
mode: str = ...,
fileobj: Optional[IO[bytes]] = ...,
preset: Optional[int] = ...,
@@ -199,21 +199,21 @@ class TarFile(Iterable[TarInfo]):
def list(self, verbose: bool = ..., *, members: Optional[List[TarInfo]] = ...) -> None: ...
def next(self) -> Optional[TarInfo]: ...
def extractall(
self, path: AnyPath = ..., members: Optional[Iterable[TarInfo]] = ..., *, numeric_owner: bool = ...
self, path: StrOrBytesPath = ..., members: Optional[Iterable[TarInfo]] = ..., *, numeric_owner: bool = ...
) -> None: ...
def extract(
self, member: Union[str, TarInfo], path: AnyPath = ..., set_attrs: bool = ..., *, numeric_owner: bool = ...
self, member: Union[str, TarInfo], path: StrOrBytesPath = ..., set_attrs: bool = ..., *, numeric_owner: bool = ...
) -> None: ...
def extractfile(self, member: Union[str, TarInfo]) -> Optional[IO[bytes]]: ...
def makedir(self, tarinfo: TarInfo, targetpath: AnyPath) -> None: ... # undocumented
def makefile(self, tarinfo: TarInfo, targetpath: AnyPath) -> None: ... # undocumented
def makeunknown(self, tarinfo: TarInfo, targetpath: AnyPath) -> None: ... # undocumented
def makefifo(self, tarinfo: TarInfo, targetpath: AnyPath) -> None: ... # undocumented
def makedev(self, tarinfo: TarInfo, targetpath: AnyPath) -> None: ... # undocumented
def makelink(self, tarinfo: TarInfo, targetpath: AnyPath) -> None: ... # undocumented
def chown(self, tarinfo: TarInfo, targetpath: AnyPath, numeric_owner: bool) -> None: ... # undocumented
def chmod(self, tarinfo: TarInfo, targetpath: AnyPath) -> None: ... # undocumented
def utime(self, tarinfo: TarInfo, targetpath: AnyPath) -> None: ... # undocumented
def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... # undocumented
def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented
if sys.version_info >= (3, 7):
def add(
self,
@@ -240,10 +240,10 @@ class TarFile(Iterable[TarInfo]):
def close(self) -> None: ...
if sys.version_info >= (3, 9):
def is_tarfile(name: Union[AnyPath, IO[bytes]]) -> bool: ...
def is_tarfile(name: Union[StrOrBytesPath, IO[bytes]]) -> bool: ...
else:
def is_tarfile(name: AnyPath) -> bool: ...
def is_tarfile(name: StrOrBytesPath) -> bool: ...
if sys.version_info < (3, 8):
def filemode(mode: int) -> str: ... # undocumented