Use PEP 585 syntax in Python 2, protobuf & _ast stubs, where possible (#6949)

This commit is contained in:
Alex Waygood
2022-01-18 15:14:03 +00:00
committed by GitHub
parent aa885ecd65
commit 8af5e0d340
264 changed files with 2217 additions and 2411 deletions

View File

@@ -7,17 +7,14 @@ from typing import (
Any,
AnyStr,
Callable,
Dict,
Generic,
Iterator,
List,
Mapping,
MutableMapping,
NamedTuple,
NoReturn,
Sequence,
Text,
Tuple,
TypeVar,
Union,
overload,
@@ -90,7 +87,7 @@ W_OK: int
X_OK: int
class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
def copy(self) -> Dict[AnyStr, AnyStr]: ...
def copy(self) -> dict[AnyStr, AnyStr]: ...
def __delitem__(self, key: AnyStr) -> None: ...
def __getitem__(self, key: AnyStr) -> AnyStr: ...
def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ...
@@ -100,9 +97,9 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
environ: _Environ[str]
if sys.platform != "win32":
# Unix only
confstr_names: Dict[str, int]
pathconf_names: Dict[str, int]
sysconf_names: Dict[str, int]
confstr_names: dict[str, int]
pathconf_names: dict[str, int]
sysconf_names: dict[str, int]
EX_OK: int
EX_USAGE: int
@@ -161,12 +158,12 @@ if sys.platform != "win32":
def getegid() -> int: ...
def geteuid() -> int: ...
def getgid() -> int: ...
def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac
def getgroups() -> list[int]: ... # Unix only, behaves differently on Mac
def initgroups(username: str, gid: int) -> None: ...
def getpgid(pid: int) -> int: ...
def getpgrp() -> int: ...
def getresuid() -> Tuple[int, int, int]: ...
def getresgid() -> Tuple[int, int, int]: ...
def getresuid() -> tuple[int, int, int]: ...
def getresgid() -> tuple[int, int, int]: ...
def getuid() -> int: ...
def setegid(egid: int) -> None: ...
def seteuid(euid: int) -> None: ...
@@ -181,7 +178,7 @@ if sys.platform != "win32":
def getsid(pid: int) -> int: ...
def setsid() -> None: ...
def setuid(uid: int) -> None: ...
def uname() -> Tuple[str, str, str, str, str]: ...
def uname() -> tuple[str, str, str, str, str]: ...
@overload
def getenv(key: Text) -> str | None: ...
@@ -198,7 +195,7 @@ def fstat(fd: int) -> Any: ...
def fsync(fd: FileDescriptorLike) -> None: ...
def lseek(fd: int, pos: int, how: int) -> int: ...
def open(file: Text, flags: int, mode: int = ...) -> int: ...
def pipe() -> Tuple[int, int]: ...
def pipe() -> tuple[int, int]: ...
def read(fd: int, n: int) -> bytes: ...
def write(fd: int, string: bytes | buffer) -> int: ...
def access(path: Text, mode: int) -> bool: ...
@@ -230,7 +227,7 @@ def symlink(source: Text, link_name: Text) -> None: ...
def unlink(path: Text) -> None: ...
# TODO: add ns, dir_fd, follow_symlinks argument
def utime(path: Text, times: Tuple[float, float] | None) -> None: ...
def utime(path: Text, times: tuple[float, float] | None) -> None: ...
if sys.platform != "win32":
# Unix only
@@ -242,7 +239,7 @@ if sys.platform != "win32":
def fstatvfs(fd: int) -> _StatVFS: ...
def ftruncate(fd: int, length: int) -> None: ...
def isatty(fd: int) -> bool: ...
def openpty() -> Tuple[int, int]: ... # some flavors of Unix
def openpty() -> tuple[int, int]: ... # some flavors of Unix
def tcgetpgrp(fd: int) -> int: ...
def tcsetpgrp(fd: int, pg: int) -> None: ...
def ttyname(fd: int) -> str: ...
@@ -258,7 +255,7 @@ if sys.platform != "win32":
def walk(
top: AnyStr, topdown: bool = ..., onerror: Callable[[OSError], Any] | None = ..., followlinks: bool = ...
) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr]]]: ...
) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]: ...
def abort() -> NoReturn: ...
# These are defined as execl(file, *args) but the first *arg is mandatory.
@@ -271,7 +268,7 @@ def execlpe(file: Text, __arg0: bytes | Text, *args: Any) -> NoReturn: ...
# The docs say `args: tuple or list of strings`
# The implementation enforces tuple or list so we can't use Sequence.
_ExecVArgs = Union[Tuple[Union[bytes, Text], ...], List[bytes], List[Text], List[Union[bytes, Text]]]
_ExecVArgs = Union[tuple[Union[bytes, Text], ...], list[bytes], list[Text], list[Union[bytes, Text]]]
def execv(path: Text, args: _ExecVArgs) -> NoReturn: ...
def execve(path: Text, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
@@ -283,22 +280,22 @@ def kill(pid: int, sig: int) -> None: ...
if sys.platform != "win32":
# Unix only
def fork() -> int: ...
def forkpty() -> Tuple[int, int]: ... # some flavors of Unix
def forkpty() -> tuple[int, int]: ... # some flavors of Unix
def killpg(__pgid: int, __signal: int) -> None: ...
def nice(increment: int) -> int: ...
def plock(op: int) -> None: ... # ???op is int?
def popen(command: str, *args, **kwargs) -> IO[Any]: ...
def popen2(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ...
def popen3(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any], IO[Any]]: ...
def popen4(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ...
def popen2(cmd: str, *args, **kwargs) -> tuple[IO[Any], IO[Any]]: ...
def popen3(cmd: str, *args, **kwargs) -> tuple[IO[Any], IO[Any], IO[Any]]: ...
def popen4(cmd: str, *args, **kwargs) -> tuple[IO[Any], IO[Any]]: ...
def spawnl(mode: int, path: Text, arg0: bytes | Text, *args: bytes | Text) -> int: ...
def spawnle(mode: int, path: Text, arg0: bytes | Text, *args: Any) -> int: ... # Imprecise sig
def spawnv(mode: int, path: Text, args: List[bytes | Text]) -> int: ...
def spawnve(mode: int, path: Text, args: List[bytes | Text], env: Mapping[str, str]) -> int: ...
def spawnv(mode: int, path: Text, args: list[bytes | Text]) -> int: ...
def spawnve(mode: int, path: Text, args: list[bytes | Text], env: Mapping[str, str]) -> int: ...
def system(command: Text) -> int: ...
def times() -> Tuple[float, float, float, float, float]: ...
def waitpid(pid: int, options: int) -> Tuple[int, int]: ...
def times() -> tuple[float, float, float, float, float]: ...
def waitpid(pid: int, options: int) -> tuple[int, int]: ...
def urandom(n: int) -> bytes: ...
if sys.platform == "win32":
@@ -308,11 +305,11 @@ else:
# Unix only
def spawnlp(mode: int, file: Text, arg0: bytes | Text, *args: bytes | Text) -> int: ...
def spawnlpe(mode: int, file: Text, arg0: bytes | Text, *args: Any) -> int: ... # Imprecise signature
def spawnvp(mode: int, file: Text, args: List[bytes | Text]) -> int: ...
def spawnvpe(mode: int, file: Text, args: List[bytes | Text], env: Mapping[str, str]) -> int: ...
def wait() -> Tuple[int, int]: ...
def wait3(options: int) -> Tuple[int, int, Any]: ...
def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ...
def spawnvp(mode: int, file: Text, args: list[bytes | Text]) -> int: ...
def spawnvpe(mode: int, file: Text, args: list[bytes | Text], env: Mapping[str, str]) -> int: ...
def wait() -> tuple[int, int]: ...
def wait3(options: int) -> tuple[int, int, Any]: ...
def wait4(pid: int, options: int) -> tuple[int, int, Any]: ...
def WCOREDUMP(status: int) -> bool: ...
def WIFCONTINUED(status: int) -> bool: ...
def WIFSTOPPED(status: int) -> bool: ...
@@ -322,7 +319,7 @@ else:
def WSTOPSIG(status: int) -> int: ...
def WTERMSIG(status: int) -> int: ...
def confstr(name: str | int) -> str | None: ...
def getloadavg() -> Tuple[float, float, float]: ...
def getloadavg() -> tuple[float, float, float]: ...
def sysconf(name: str | int) -> int: ...
def tmpfile() -> IO[Any]: ...

View File

@@ -1,6 +1,6 @@
import os
import sys
from typing import Any, AnyStr, Callable, List, Sequence, Text, Tuple, TypeVar, overload
from typing import Any, AnyStr, Callable, Sequence, Text, TypeVar, overload
_T = TypeVar("_T")
@@ -74,11 +74,11 @@ def relpath(path: Text, start: Text | None = ...) -> Text: ...
def samefile(f1: Text, f2: Text) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ...
def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def split(p: AnyStr) -> tuple[AnyStr, AnyStr]: ...
def splitdrive(p: AnyStr) -> tuple[AnyStr, AnyStr]: ...
def splitext(p: AnyStr) -> tuple[AnyStr, AnyStr]: ...
if sys.platform == "win32":
def splitunc(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
def splitunc(p: AnyStr) -> tuple[AnyStr, AnyStr]: ... # deprecated
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
def walk(path: AnyStr, visit: Callable[[_T, AnyStr, list[AnyStr]], Any], arg: _T) -> None: ...