Use TypeAlias where possible for type aliases (#7630)

This commit is contained in:
Alex Waygood
2022-04-16 02:01:00 +01:00
committed by GitHub
parent c0e6dd3f3f
commit 740193a8fc
218 changed files with 760 additions and 625 deletions

View File

@@ -7,17 +7,17 @@ from datetime import datetime
from io import BytesIO
from types import TracebackType
from typing import Any, Callable, Iterable, Mapping, Protocol, Union, overload
from typing_extensions import Literal
from typing_extensions import Literal, TypeAlias
class _SupportsTimeTuple(Protocol):
def timetuple(self) -> time.struct_time: ...
_DateTimeComparable = DateTime | datetime | str | _SupportsTimeTuple
_Marshallable = (
_DateTimeComparable: TypeAlias = DateTime | datetime | str | _SupportsTimeTuple
_Marshallable: TypeAlias = (
bool | int | float | str | bytes | None | tuple[Any, ...] | list[Any] | dict[Any, Any] | datetime | DateTime | Binary
)
_XMLDate = int | datetime | tuple[int, ...] | time.struct_time
_HostType = Union[tuple[str, dict[str, str]], str]
_XMLDate: TypeAlias = int | datetime | tuple[int, ...] | time.struct_time
_HostType: TypeAlias = Union[tuple[str, dict[str, str]], str]
def escape(s: str) -> str: ... # undocumented

View File

@@ -4,10 +4,11 @@ import socketserver
import sys
from datetime import datetime
from typing import Any, Callable, Iterable, Mapping, Pattern, Protocol
from typing_extensions import TypeAlias
from xmlrpc.client import Fault
# TODO: Recursive type on tuple, list, dict
_Marshallable = None | bool | int | float | str | bytes | tuple[Any, ...] | list[Any] | dict[Any, Any] | datetime
_Marshallable: TypeAlias = None | bool | int | float | str | bytes | tuple[Any, ...] | list[Any] | dict[Any, Any] | datetime
# The dispatch accepts anywhere from 0 to N arguments, no easy way to allow this in mypy
class _DispatchArity0(Protocol):
@@ -30,7 +31,9 @@ class _DispatchArity4(Protocol):
class _DispatchArityN(Protocol):
def __call__(self, *args: _Marshallable) -> _Marshallable: ...
_DispatchProtocol = _DispatchArity0 | _DispatchArity1 | _DispatchArity2 | _DispatchArity3 | _DispatchArity4 | _DispatchArityN
_DispatchProtocol: TypeAlias = (
_DispatchArity0 | _DispatchArity1 | _DispatchArity2 | _DispatchArity3 | _DispatchArity4 | _DispatchArityN
)
def resolve_dotted_attribute(obj: Any, attr: str, allow_dotted_names: bool = ...) -> Any: ... # undocumented
def list_public_methods(obj: Any) -> list[str]: ... # undocumented