Skip to content

Use short type var names per PEP 8 #4553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions stdlib/2and3/mailbox.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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: ...
Expand All @@ -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]):
Expand Down
18 changes: 9 additions & 9 deletions stdlib/2and3/unicodedata.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ 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):
def is_normalized(__form: str, __unistr: str) -> bool: ...

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
Expand All @@ -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]: ...
8 changes: 4 additions & 4 deletions stdlib/3/multiprocessing/dummy/connection.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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: ...
Expand All @@ -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: ...
Expand Down
34 changes: 16 additions & 18 deletions stdlib/3/statistics.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,43 @@ 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): ...

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:
Expand Down
2 changes: 1 addition & 1 deletion third_party/2and3/click/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_PathType = Any
_PathType = AnyStr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_PathType is never used as a type variable, it's just a glorified Union[str, bytes] return type. (Which means I can leave my obligatory link to python/typing#566 here.)


class Path(ParamType):
def __init__(
Expand Down
6 changes: 3 additions & 3 deletions third_party/2and3/google/protobuf/json_format.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand All @@ -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: ...
22 changes: 11 additions & 11 deletions third_party/2and3/jinja2/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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] = ...,
Expand Down
4 changes: 2 additions & 2 deletions third_party/2and3/werkzeug/wrappers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down