mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-30 08:04:24 +08:00
Use explicit type aliases in _typeshed (#7534)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
mypy==0.942
|
||||
pytype==2022.3.21; platform_system != "Windows" and python_version < "3.10"
|
||||
pytype==2022.03.29; platform_system != "Windows" and python_version < "3.10"
|
||||
# must match .pre-commit-config.yaml
|
||||
black==22.1.0
|
||||
flake8==4.0.1
|
||||
|
||||
@@ -58,7 +58,7 @@ class SupportsDunderGE(Protocol):
|
||||
|
||||
class SupportsAllComparisons(SupportsDunderLT, SupportsDunderGT, SupportsDunderLE, SupportsDunderGE, Protocol): ...
|
||||
|
||||
SupportsRichComparison = SupportsDunderLT | SupportsDunderGT
|
||||
SupportsRichComparison: TypeAlias = SupportsDunderLT | SupportsDunderGT
|
||||
SupportsRichComparisonT = TypeVar("SupportsRichComparisonT", bound=SupportsRichComparison) # noqa: Y001
|
||||
|
||||
class SupportsDivMod(Protocol[_T_contra, _T_co]):
|
||||
@@ -95,9 +95,9 @@ class SupportsItemAccess(SupportsGetItem[_KT_contra, _VT], Protocol[_KT_contra,
|
||||
def __delitem__(self, __v: _KT_contra) -> None: ...
|
||||
|
||||
# These aliases are simple strings in Python 2.
|
||||
StrPath = str | PathLike[str] # stable
|
||||
BytesPath = bytes | PathLike[bytes] # stable
|
||||
StrOrBytesPath = str | bytes | PathLike[str] | PathLike[bytes] # stable
|
||||
StrPath: TypeAlias = str | PathLike[str] # stable
|
||||
BytesPath: TypeAlias = bytes | PathLike[bytes] # stable
|
||||
StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes] # stable
|
||||
|
||||
OpenTextModeUpdating = Literal[
|
||||
"r+",
|
||||
@@ -133,10 +133,10 @@ OpenTextModeUpdating = Literal[
|
||||
"t+x",
|
||||
"+tx",
|
||||
]
|
||||
OpenTextModeWriting = Literal["w", "wt", "tw", "a", "at", "ta", "x", "xt", "tx"]
|
||||
OpenTextModeReading = Literal["r", "rt", "tr", "U", "rU", "Ur", "rtU", "rUt", "Urt", "trU", "tUr", "Utr"]
|
||||
OpenTextMode = OpenTextModeUpdating | OpenTextModeWriting | OpenTextModeReading
|
||||
OpenBinaryModeUpdating = Literal[
|
||||
OpenTextModeWriting: TypeAlias = Literal["w", "wt", "tw", "a", "at", "ta", "x", "xt", "tx"]
|
||||
OpenTextModeReading: TypeAlias = Literal["r", "rt", "tr", "U", "rU", "Ur", "rtU", "rUt", "Urt", "trU", "tUr", "Utr"]
|
||||
OpenTextMode: TypeAlias = OpenTextModeUpdating | OpenTextModeWriting | OpenTextModeReading
|
||||
OpenBinaryModeUpdating: TypeAlias = Literal[
|
||||
"rb+",
|
||||
"r+b",
|
||||
"+rb",
|
||||
@@ -162,16 +162,16 @@ OpenBinaryModeUpdating = Literal[
|
||||
"b+x",
|
||||
"+bx",
|
||||
]
|
||||
OpenBinaryModeWriting = Literal["wb", "bw", "ab", "ba", "xb", "bx"]
|
||||
OpenBinaryModeReading = Literal["rb", "br", "rbU", "rUb", "Urb", "brU", "bUr", "Ubr"]
|
||||
OpenBinaryMode = OpenBinaryModeUpdating | OpenBinaryModeReading | OpenBinaryModeWriting
|
||||
OpenBinaryModeWriting: TypeAlias = Literal["wb", "bw", "ab", "ba", "xb", "bx"]
|
||||
OpenBinaryModeReading: TypeAlias = Literal["rb", "br", "rbU", "rUb", "Urb", "brU", "bUr", "Ubr"]
|
||||
OpenBinaryMode: TypeAlias = OpenBinaryModeUpdating | OpenBinaryModeReading | OpenBinaryModeWriting
|
||||
|
||||
# stable
|
||||
class HasFileno(Protocol):
|
||||
def fileno(self) -> int: ...
|
||||
|
||||
FileDescriptor = int # stable
|
||||
FileDescriptorLike = int | HasFileno # stable
|
||||
FileDescriptor: TypeAlias = int # stable
|
||||
FileDescriptorLike: TypeAlias = int | HasFileno # stable
|
||||
|
||||
# stable
|
||||
class SupportsRead(Protocol[_T_co]):
|
||||
@@ -189,13 +189,13 @@ class SupportsNoArgReadline(Protocol[_T_co]):
|
||||
class SupportsWrite(Protocol[_T_contra]):
|
||||
def write(self, __s: _T_contra) -> object: ...
|
||||
|
||||
ReadOnlyBuffer = bytes # stable
|
||||
ReadOnlyBuffer: TypeAlias = bytes # stable
|
||||
# Anything that implements the read-write buffer interface.
|
||||
# The buffer interface is defined purely on the C level, so we cannot define a normal Protocol
|
||||
# for it. Instead we have to list the most common stdlib buffer classes in a Union.
|
||||
WriteableBuffer = bytearray | memoryview | array.array[Any] | mmap.mmap | ctypes._CData # stable
|
||||
WriteableBuffer: TypeAlias = bytearray | memoryview | array.array[Any] | mmap.mmap | ctypes._CData # stable
|
||||
# Same as _WriteableBuffer, but also includes read-only buffer types (like bytes).
|
||||
ReadableBuffer = ReadOnlyBuffer | WriteableBuffer # stable
|
||||
ReadableBuffer: TypeAlias = ReadOnlyBuffer | WriteableBuffer # stable
|
||||
|
||||
# stable
|
||||
if sys.version_info >= (3, 10):
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import Any, Protocol
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
DBAPITypeCode = Any | None
|
||||
DBAPITypeCode: TypeAlias = Any | None
|
||||
# Strictly speaking, this should be a Sequence, but the type system does
|
||||
# not support fixed-length sequences.
|
||||
DBAPIColumnDescription = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None]
|
||||
DBAPIColumnDescription: TypeAlias = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None]
|
||||
|
||||
class DBAPIConnection(Protocol):
|
||||
def close(self) -> object: ...
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
from sys import _OptExcInfo
|
||||
from typing import Any, Callable, Iterable, Protocol
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
# stable
|
||||
class StartResponse(Protocol):
|
||||
@@ -11,8 +12,8 @@ class StartResponse(Protocol):
|
||||
self, status: str, headers: list[tuple[str, str]], exc_info: _OptExcInfo | None = ...
|
||||
) -> Callable[[bytes], Any]: ...
|
||||
|
||||
WSGIEnvironment = dict[str, Any] # stable
|
||||
WSGIApplication = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] # stable
|
||||
WSGIEnvironment: TypeAlias = dict[str, Any] # stable
|
||||
WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] # stable
|
||||
|
||||
# WSGI input streams per PEP 3333, stable
|
||||
class InputStream(Protocol):
|
||||
|
||||
Reference in New Issue
Block a user