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,5 +1,5 @@
import sys
from _typeshed import AnyPath
from _typeshed import StrOrBytesPath
from types import TracebackType
from typing import IO, Any, AnyStr, Callable, Generic, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union, overload
from typing_extensions import Literal
@@ -24,15 +24,15 @@ if sys.version_info >= (3, 9):
_FILE = Union[None, int, IO[Any]]
_TXT = Union[bytes, str]
if sys.version_info >= (3, 8):
_CMD = Union[AnyPath, Sequence[AnyPath]]
_CMD = Union[StrOrBytesPath, Sequence[StrOrBytesPath]]
else:
# Python 3.6 doesn't support _CMD being a single PathLike.
# See: https://bugs.python.org/issue31961
_CMD = Union[_TXT, Sequence[AnyPath]]
_CMD = Union[_TXT, Sequence[StrOrBytesPath]]
if sys.platform == "win32":
_ENV = Mapping[str, str]
else:
_ENV = Union[Mapping[bytes, AnyPath], Mapping[str, AnyPath]]
_ENV = Union[Mapping[bytes, StrOrBytesPath], Mapping[str, StrOrBytesPath]]
_S = TypeVar("_S")
_T = TypeVar("_T")
@@ -56,14 +56,14 @@ if sys.version_info >= (3, 7):
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -84,14 +84,14 @@ if sys.version_info >= (3, 7):
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -112,14 +112,14 @@ if sys.version_info >= (3, 7):
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -140,14 +140,14 @@ if sys.version_info >= (3, 7):
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
*,
universal_newlines: Literal[True],
@@ -169,14 +169,14 @@ if sys.version_info >= (3, 7):
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: Literal[False] = ...,
startupinfo: Any = ...,
@@ -197,14 +197,14 @@ if sys.version_info >= (3, 7):
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -228,14 +228,14 @@ else:
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -254,14 +254,14 @@ else:
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -280,14 +280,14 @@ else:
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
*,
universal_newlines: Literal[True],
@@ -307,14 +307,14 @@ else:
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: Literal[False] = ...,
startupinfo: Any = ...,
@@ -333,14 +333,14 @@ else:
def run(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -360,14 +360,14 @@ else:
def call(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -383,14 +383,14 @@ def call(
def check_call(
args: _CMD,
bufsize: int = ...,
executable: AnyPath = ...,
executable: StrOrBytesPath = ...,
stdin: _FILE = ...,
stdout: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -407,13 +407,13 @@ if sys.version_info >= (3, 7):
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -432,13 +432,13 @@ if sys.version_info >= (3, 7):
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -457,13 +457,13 @@ if sys.version_info >= (3, 7):
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -482,13 +482,13 @@ if sys.version_info >= (3, 7):
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
*,
universal_newlines: Literal[True],
@@ -508,13 +508,13 @@ if sys.version_info >= (3, 7):
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: Literal[False] = ...,
startupinfo: Any = ...,
@@ -533,13 +533,13 @@ if sys.version_info >= (3, 7):
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -560,13 +560,13 @@ else:
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -584,13 +584,13 @@ else:
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -608,13 +608,13 @@ else:
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
startupinfo: Any = ...,
creationflags: int = ...,
@@ -632,13 +632,13 @@ else:
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: Literal[False] = ...,
startupinfo: Any = ...,
@@ -656,13 +656,13 @@ else:
def check_output(
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: _FILE = ...,
stderr: _FILE = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Any = ...,
@@ -724,14 +724,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Optional[Any] = ...,
@@ -749,14 +749,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Optional[Any] = ...,
@@ -774,14 +774,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
*,
universal_newlines: Literal[True],
@@ -800,14 +800,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Optional[Any] = ...,
@@ -825,14 +825,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: Literal[False] = ...,
startupinfo: Optional[Any] = ...,
@@ -850,14 +850,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Optional[Any] = ...,
@@ -876,14 +876,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Optional[Any] = ...,
@@ -900,14 +900,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Optional[Any] = ...,
@@ -924,14 +924,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
*,
universal_newlines: Literal[True],
@@ -949,14 +949,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: Literal[False] = ...,
startupinfo: Optional[Any] = ...,
@@ -973,14 +973,14 @@ class Popen(Generic[AnyStr]):
cls,
args: _CMD,
bufsize: int = ...,
executable: Optional[AnyPath] = ...,
executable: Optional[StrOrBytesPath] = ...,
stdin: Optional[_FILE] = ...,
stdout: Optional[_FILE] = ...,
stderr: Optional[_FILE] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[AnyPath] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[_ENV] = ...,
universal_newlines: bool = ...,
startupinfo: Optional[Any] = ...,