From 5635688deb60b25bbf65fedad155cd521546f63c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 17 Sep 2020 18:02:27 +0200 Subject: [PATCH] Use short type var names per PEP 8 Closes: #1872 --- stdlib/2and3/mailbox.pyi | 36 +++++++++---------- stdlib/2and3/unicodedata.pyi | 18 +++++----- stdlib/3/multiprocessing/dummy/connection.pyi | 8 ++--- stdlib/3/statistics.pyi | 34 +++++++++--------- third_party/2and3/click/types.pyi | 2 +- .../2and3/google/protobuf/json_format.pyi | 6 ++-- third_party/2and3/jinja2/utils.pyi | 22 ++++++------ third_party/2and3/werkzeug/wrappers.pyi | 4 +-- 8 files changed, 64 insertions(+), 66 deletions(-) diff --git a/stdlib/2and3/mailbox.pyi b/stdlib/2and3/mailbox.pyi index a089fd3b8175..b03621f84dcd 100644 --- a/stdlib/2and3/mailbox.pyi +++ b/stdlib/2and3/mailbox.pyi @@ -25,7 +25,7 @@ from typing import ( from typing_extensions import Literal _T = TypeVar("_T") -_MessageType = TypeVar("_MessageType", bound=Message) +_MT = TypeVar("_MT", bound=Message) _MessageData = Union[email.message.Message, bytes, str, IO[str], IO[bytes]] class _HasIteritems(Protocol): @@ -36,41 +36,41 @@ class _HasItems(Protocol): linesep: bytes -class Mailbox(Generic[_MessageType]): +class Mailbox(Generic[_MT]): _path: Union[bytes, str] # undocumented - _factory: Optional[Callable[[IO[Any]], _MessageType]] # undocumented - def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], _MessageType]] = ..., create: bool = ...) -> None: ... + _factory: Optional[Callable[[IO[Any]], _MT]] # undocumented + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], _MT]] = ..., create: bool = ...) -> None: ... def add(self, message: _MessageData) -> str: ... def remove(self, key: str) -> None: ... def __delitem__(self, key: str) -> None: ... def discard(self, key: str) -> None: ... def __setitem__(self, key: str, message: _MessageData) -> None: ... @overload - def get(self, key: str, default: None = ...) -> Optional[_MessageType]: ... + def get(self, key: str, default: None = ...) -> Optional[_MT]: ... @overload - def get(self, key: str, default: _T) -> Union[_MessageType, _T]: ... - def __getitem__(self, key: str) -> _MessageType: ... - def get_message(self, key: str) -> _MessageType: ... + def get(self, key: str, default: _T) -> Union[_MT, _T]: ... + def __getitem__(self, key: str) -> _MT: ... + def get_message(self, key: str) -> _MT: ... def get_string(self, key: str) -> str: ... def get_bytes(self, key: str) -> bytes: ... # As '_ProxyFile' doesn't implement the full IO spec, and BytesIO is incompatible with it, get_file return is Any here def get_file(self, key: str) -> Any: ... def iterkeys(self) -> Iterator[str]: ... def keys(self) -> List[str]: ... - def itervalues(self) -> Iterator[_MessageType]: ... - def __iter__(self) -> Iterator[_MessageType]: ... - def values(self) -> List[_MessageType]: ... - def iteritems(self) -> Iterator[Tuple[str, _MessageType]]: ... - def items(self) -> List[Tuple[str, _MessageType]]: ... + def itervalues(self) -> Iterator[_MT]: ... + def __iter__(self) -> Iterator[_MT]: ... + def values(self) -> List[_MT]: ... + def iteritems(self) -> Iterator[Tuple[str, _MT]]: ... + def items(self) -> List[Tuple[str, _MT]]: ... def __contains__(self, key: str) -> bool: ... def __len__(self) -> int: ... def clear(self) -> None: ... @overload - def pop(self, key: str, default: None = ...) -> Optional[_MessageType]: ... + def pop(self, key: str, default: None = ...) -> Optional[_MT]: ... @overload - def pop(self, key: str, default: _T = ...) -> Union[_MessageType, _T]: ... - def popitem(self) -> Tuple[str, _MessageType]: ... + def pop(self, key: str, default: _T = ...) -> Union[_MT, _T]: ... + def popitem(self) -> Tuple[str, _MT]: ... def update(self, arg: Optional[Union[_HasIteritems, _HasItems, Iterable[Tuple[str, _MessageData]]]] = ...) -> None: ... def flush(self) -> None: ... def lock(self) -> None: ... @@ -91,9 +91,9 @@ class Maildir(Mailbox[MaildirMessage]): def clean(self) -> None: ... def next(self) -> Optional[str]: ... -class _singlefileMailbox(Mailbox[_MessageType]): ... +class _singlefileMailbox(Mailbox[_MT]): ... -class _mboxMMDF(_singlefileMailbox[_MessageType]): +class _mboxMMDF(_singlefileMailbox[_MT]): def get_file(self, key: str) -> _PartialFile[bytes]: ... class mbox(_mboxMMDF[mboxMessage]): diff --git a/stdlib/2and3/unicodedata.pyi b/stdlib/2and3/unicodedata.pyi index 1aa9ffb96fa2..a83d79ff2ed0 100644 --- a/stdlib/2and3/unicodedata.pyi +++ b/stdlib/2and3/unicodedata.pyi @@ -5,14 +5,14 @@ ucd_3_2_0: UCD ucnhash_CAPI: Any unidata_version: str -_default = TypeVar("_default") +_T = TypeVar("_T") def bidirectional(__chr: Text) -> Text: ... def category(__chr: Text) -> Text: ... def combining(__chr: Text) -> int: ... -def decimal(__chr: Text, __default: _default = ...) -> Union[int, _default]: ... +def decimal(__chr: Text, __default: _T = ...) -> Union[int, _T]: ... def decomposition(__chr: Text) -> Text: ... -def digit(__chr: Text, __default: _default = ...) -> Union[int, _default]: ... +def digit(__chr: Text, __default: _T = ...) -> Union[int, _T]: ... def east_asian_width(__chr: Text) -> Text: ... if sys.version_info >= (3, 8): @@ -20,9 +20,9 @@ if sys.version_info >= (3, 8): def lookup(__name: Union[Text, bytes]) -> Text: ... def mirrored(__chr: Text) -> int: ... -def name(__chr: Text, __default: _default = ...) -> Union[Text, _default]: ... +def name(__chr: Text, __default: _T = ...) -> Union[Text, _T]: ... def normalize(__form: Text, __unistr: Text) -> Text: ... -def numeric(__chr: Text, __default: _default = ...) -> Union[float, _default]: ... +def numeric(__chr: Text, __default: _T = ...) -> Union[float, _T]: ... class UCD(object): # The methods below are constructed from the same array in C @@ -31,12 +31,12 @@ class UCD(object): def bidirectional(self, __chr: Text) -> str: ... def category(self, __chr: Text) -> str: ... def combining(self, __chr: Text) -> int: ... - def decimal(self, __chr: Text, __default: _default = ...) -> Union[int, _default]: ... + def decimal(self, __chr: Text, __default: _T = ...) -> Union[int, _T]: ... def decomposition(self, __chr: Text) -> str: ... - def digit(self, __chr: Text, __default: _default = ...) -> Union[int, _default]: ... + def digit(self, __chr: Text, __default: _T = ...) -> Union[int, _T]: ... def east_asian_width(self, __chr: Text) -> str: ... def lookup(self, __name: Union[Text, bytes]) -> Text: ... def mirrored(self, __chr: Text) -> int: ... - def name(self, __chr: Text, __default: _default = ...) -> Union[Text, _default]: ... + def name(self, __chr: Text, __default: _T = ...) -> Union[Text, _T]: ... def normalize(self, __form: Text, __unistr: Text) -> Text: ... - def numeric(self, __chr: Text, __default: _default = ...) -> Union[float, _default]: ... + def numeric(self, __chr: Text, __default: _T = ...) -> Union[float, _T]: ... diff --git a/stdlib/3/multiprocessing/dummy/connection.pyi b/stdlib/3/multiprocessing/dummy/connection.pyi index 4f9f716959d4..961dd8254e62 100644 --- a/stdlib/3/multiprocessing/dummy/connection.pyi +++ b/stdlib/3/multiprocessing/dummy/connection.pyi @@ -4,8 +4,8 @@ from typing import Any, List, Optional, Tuple, Type, TypeVar, Union families: List[None] -_TConnection = TypeVar("_TConnection", bound=Connection) -_TListener = TypeVar("_TListener", bound=Listener) +_CoT = TypeVar("_CoT", bound=Connection) +_LiT = TypeVar("_LiT", bound=Listener) _Address = Union[str, Tuple[str, int]] class Connection(object): @@ -15,7 +15,7 @@ class Connection(object): recv_bytes: Any send: Any send_bytes: Any - def __enter__(self: _TConnection) -> _TConnection: ... + def __enter__(self: _CoT) -> _CoT: ... def __exit__( self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] ) -> None: ... @@ -27,7 +27,7 @@ class Listener(object): _backlog_queue: Optional[Queue[Any]] @property def address(self) -> Optional[Queue[Any]]: ... - def __enter__(self: _TListener) -> _TListener: ... + def __enter__(self: _LiT) -> _LiT: ... def __exit__( self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] ) -> None: ... diff --git a/stdlib/3/statistics.pyi b/stdlib/3/statistics.pyi index 1281a980ee4f..b5da87c166fa 100644 --- a/stdlib/3/statistics.pyi +++ b/stdlib/3/statistics.pyi @@ -7,16 +7,14 @@ from typing import Any, Hashable, Iterable, List, Optional, Protocol, SupportsFl _T = TypeVar("_T") # Most functions in this module accept homogeneous collections of one of these types -_Number = TypeVar("_Number", float, Decimal, Fraction) +_NumT = TypeVar("_NumT", float, Decimal, Fraction) # Used in median_high, median_low class _Sortable(Protocol): def __lt__(self, other: Any) -> bool: ... -_SortableT = TypeVar("_SortableT", bound=_Sortable) - -# Used in mode, multimode -_HashableT = TypeVar("_HashableT", bound=Hashable) +_SortT = TypeVar("_SortT", bound=_Sortable) +_HashT = TypeVar("_HashT", bound=Hashable) class StatisticsError(ValueError): ... @@ -24,28 +22,28 @@ if sys.version_info >= (3, 8): def fmean(data: Iterable[SupportsFloat]) -> float: ... def geometric_mean(data: Iterable[SupportsFloat]) -> float: ... -def mean(data: Iterable[_Number]) -> _Number: ... +def mean(data: Iterable[_NumT]) -> _NumT: ... if sys.version_info >= (3, 6): - def harmonic_mean(data: Iterable[_Number]) -> _Number: ... + def harmonic_mean(data: Iterable[_NumT]) -> _NumT: ... -def median(data: Iterable[_Number]) -> _Number: ... -def median_low(data: Iterable[_SortableT]) -> _SortableT: ... -def median_high(data: Iterable[_SortableT]) -> _SortableT: ... -def median_grouped(data: Iterable[_Number], interval: _Number = ...) -> _Number: ... -def mode(data: Iterable[_HashableT]) -> _HashableT: ... +def median(data: Iterable[_NumT]) -> _NumT: ... +def median_low(data: Iterable[_SortT]) -> _SortT: ... +def median_high(data: Iterable[_SortT]) -> _SortT: ... +def median_grouped(data: Iterable[_NumT], interval: _NumT = ...) -> _NumT: ... +def mode(data: Iterable[_HashT]) -> _HashT: ... if sys.version_info >= (3, 8): - def multimode(data: Iterable[_HashableT]) -> List[_HashableT]: ... + def multimode(data: Iterable[_HashT]) -> List[_HashT]: ... -def pstdev(data: Iterable[_Number], mu: Optional[_Number] = ...) -> _Number: ... -def pvariance(data: Iterable[_Number], mu: Optional[_Number] = ...) -> _Number: ... +def pstdev(data: Iterable[_NumT], mu: Optional[_NumT] = ...) -> _NumT: ... +def pvariance(data: Iterable[_NumT], mu: Optional[_NumT] = ...) -> _NumT: ... if sys.version_info >= (3, 8): - def quantiles(data: Iterable[_Number], *, n: int = ..., method: str = ...) -> List[_Number]: ... + def quantiles(data: Iterable[_NumT], *, n: int = ..., method: str = ...) -> List[_NumT]: ... -def stdev(data: Iterable[_Number], xbar: Optional[_Number] = ...) -> _Number: ... -def variance(data: Iterable[_Number], xbar: Optional[_Number] = ...) -> _Number: ... +def stdev(data: Iterable[_NumT], xbar: Optional[_NumT] = ...) -> _NumT: ... +def variance(data: Iterable[_NumT], xbar: Optional[_NumT] = ...) -> _NumT: ... if sys.version_info >= (3, 8): class NormalDist: diff --git a/third_party/2and3/click/types.pyi b/third_party/2and3/click/types.pyi index 923e20275be6..91d616691c14 100644 --- a/third_party/2and3/click/types.pyi +++ b/third_party/2and3/click/types.pyi @@ -55,7 +55,7 @@ class IntParamType(ParamType): class IntRange(IntParamType): def __init__(self, min: Optional[int] = ..., max: Optional[int] = ..., clamp: bool = ...) -> None: ... -_PathType = TypeVar("_PathType", str, bytes) +_PathType = Any class Path(ParamType): def __init__( diff --git a/third_party/2and3/google/protobuf/json_format.pyi b/third_party/2and3/google/protobuf/json_format.pyi index 8ccc905757a3..628dab58fa00 100644 --- a/third_party/2and3/google/protobuf/json_format.pyi +++ b/third_party/2and3/google/protobuf/json_format.pyi @@ -2,7 +2,7 @@ from typing import Any, Dict, Text, TypeVar, Union from google.protobuf.message import Message -_MessageVar = TypeVar("_MessageVar", bound=Message) +_M = TypeVar("_M", bound=Message) class Error(Exception): ... class ParseError(Error): ... @@ -22,5 +22,5 @@ def MessageToDict( preserving_proto_field_name: bool = ..., use_integers_for_enums: bool = ..., ) -> Dict[Text, Any]: ... -def Parse(text: Union[bytes, Text], message: _MessageVar, ignore_unknown_fields: bool = ...) -> _MessageVar: ... -def ParseDict(js_dict: Any, message: _MessageVar, ignore_unknown_fields: bool = ...) -> _MessageVar: ... +def Parse(text: Union[bytes, Text], message: _M, ignore_unknown_fields: bool = ...) -> _M: ... +def ParseDict(js_dict: Any, message: _M, ignore_unknown_fields: bool = ...) -> _M: ... diff --git a/third_party/2and3/jinja2/utils.pyi b/third_party/2and3/jinja2/utils.pyi index 3d1b1cccf2d1..e697ec2b7df6 100644 --- a/third_party/2and3/jinja2/utils.pyi +++ b/third_party/2and3/jinja2/utils.pyi @@ -8,24 +8,24 @@ missing: Any internal_code: Any concat: Any -_CallableT = TypeVar("_CallableT", bound=Callable[..., Any]) +_CT = TypeVar("_CT", bound=Callable[..., Any]) -class _ContextFunction(Protocol[_CallableT]): +class _ContextFunction(Protocol[_CT]): contextfunction: Literal[True] - __call__: _CallableT + __call__: _CT -class _EvalContextFunction(Protocol[_CallableT]): +class _EvalContextFunction(Protocol[_CT]): evalcontextfunction: Literal[True] - __call__: _CallableT + __call__: _CT -class _EnvironmentFunction(Protocol[_CallableT]): +class _EnvironmentFunction(Protocol[_CT]): environmentfunction: Literal[True] - __call__: _CallableT + __call__: _CT -def contextfunction(f: _CallableT) -> _ContextFunction[_CallableT]: ... -def evalcontextfunction(f: _CallableT) -> _EvalContextFunction[_CallableT]: ... -def environmentfunction(f: _CallableT) -> _EnvironmentFunction[_CallableT]: ... -def internalcode(f: _CallableT) -> _CallableT: ... +def contextfunction(f: _CT) -> _ContextFunction[_CT]: ... +def evalcontextfunction(f: _CT) -> _EvalContextFunction[_CT]: ... +def environmentfunction(f: _CT) -> _EnvironmentFunction[_CT]: ... +def internalcode(f: _CT) -> _CT: ... def is_undefined(obj: object) -> bool: ... def select_autoescape( enabled_extensions: Iterable[str] = ..., diff --git a/third_party/2and3/werkzeug/wrappers.pyi b/third_party/2and3/werkzeug/wrappers.pyi index ed9a5fb417e1..ff780bf315aa 100644 --- a/third_party/2and3/werkzeug/wrappers.pyi +++ b/third_party/2and3/werkzeug/wrappers.pyi @@ -104,7 +104,7 @@ class BaseRequest: is_multiprocess: bool is_run_once: bool -_OnCloseT = TypeVar("_OnCloseT", bound=Callable[[], Any]) +_OCT = TypeVar("_OCT", bound=Callable[[], Any]) _SelfT = TypeVar("_SelfT", bound=BaseResponse) class BaseResponse: @@ -128,7 +128,7 @@ class BaseResponse: content_type: Optional[Text] = ..., direct_passthrough: bool = ..., ) -> None: ... - def call_on_close(self, func: _OnCloseT) -> _OnCloseT: ... + def call_on_close(self, func: _OCT) -> _OCT: ... @classmethod def force_type(cls: Type[_SelfT], response: object, environ: Optional[WSGIEnvironment] = ...) -> _SelfT: ... @classmethod